Msg#: 4519140 posted 8:20 pm on Nov 14, 2012 (gmt 0)
So if you have a search feature, and drop down boxes are included, but you want to list an option in the drop down box as ALL, displaying all e.g. price ranges, and in your mysql query you have: SELECT * FROM `products` WHERE `price`=$priceRange AND `locaction`=$location
Then what if you want to choose all? Obviously this will not work. So how is this usually done? Do you have to use switch statements for if isset each variable, and the combination of each, as you must also enter the AND into the query too. And what if you have 10 or even more search parameters? There are too many combinations.
Msg#: 4519140 posted 8:27 pm on Nov 14, 2012 (gmt 0)
You'll need to include some sort of conditional logic in building the SELECT statement. Use the "`price`=$priceRange" unless all is selected. (I don't know PHP so I can't give you the exact way to write it.) Include the same logic for all your other conditionals.
If every conditional can be selected for all, you'll also need an initial "1=1" conditional. Something like the following in pseudo code: SELECT * FROM `products` WHERE 1=1 IF ($priceRange<>'*') AND `price`=$priceRange IF ($location<>'*') AND `locaction`=$location ...
(NOTE: the psuedocode is used to build the SQL statement in PHP.)