|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Multiple searchfields in my result page(ASP vbScript Dreamweaver)
Hi there,
I'm trying to do a search on my database through multiple search fields i've tried to use 'AND' in my sql but then there are no results. When i search for one value through one inputfield everything works oke but when i add an input field on my search page for a combined search nothing works!!. could someboby help me?! Thanx, |
|
#2
|
|||
|
|||
|
I figured out how to search multiple fields but when i leave the first field blank then the search doesn't work any more. I've tried to change the 'And' into 'Or" but then the entire database is shown.!!
|
|
#3
|
|||
|
|||
|
by the way this is the code:
SELECT Vissoort, Plaats, vanglocatie, Aas FROM Beettabel WHERE Vissoort like 'MMColParam' AND Plaats like 'MMColPlaats' AND Aas like 'MMColAas' AND Weer like 'MMColWeer' |
|
#4
|
||||
|
||||
|
Well, the problem is because if you leave a field blank in your search, all your AND statements make the search look for only fields that match all the other search terms, and have a blank field, which apparently doesn't exist. (Maybe because all your database entries have all fields full.) When you use OR, it finds all entries that match any one of the search terms, which apparently is the whole database.
You could avoid this by using some logic before your search, to see if any fields are empty, and either prompting the user to fill in a value for that field, or running the search without that parameter. I don't have an elegant way to do this, but if you need more help, I can post something that should at least function. HTH |
|
#5
|
|||
|
|||
|
Thanks, but i think there is an other problem because when i only fill in the first field and i leave the rest of the fields empty(although they are full in the database) i do get resultes on the first field! i could be wrong thou.
|
|
#6
|
||||
|
||||
|
Not knowing more about your database set up, I'm not really sure why you are getting the results you are. However, if the results you get are correct unless the first field is blank, try (untested)
Code:
If request.form("MMColParam")="" Then
my_sql = "SELECT Vissoort, Plaats, vanglocatie, Aas
FROM Beettabel
WHERE Plaats like 'MMColPlaats' AND Aas like 'MMColAas' AND Weer like 'MMColWeer'"
Else
my_sql = "SELECT Vissoort, Plaats, vanglocatie, Aas
FROM Beettabel
WHERE Vissoort like 'MMColParam' AND Plaats like 'MMColPlaats' AND Aas like 'MMColAas' AND Weer like 'MMColWeer'"
I haven't tried this, and I'm not sure the quotes are escaped correctly, but you get the idea, I hope. If the query works as long as the first field isn't blank, then check, and if the first field is in fact blank, don't use it in the query. edit: bah, stupid code spacing. Sorry, thats pretty ugly. ![]()
__________________
--Dave-- U2kgSG9jIExlZ2VyZSBTY2lzLCBOaW1pdW0gRXJ1ZGl0aW9uaXMgSGFiZXM= |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Multiple searchfields in my result page(ASP vbScript Dreamweaver) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|