I’m just an basic SQL user (mySQL+php now). I have search box with multiple input (conditions).
For example:
Color: ____
Size: ____
Price: ___
Condition: ___
Discount %: ___
Hit Count: ___
etc, many more …………
User may input 1 or more fileds.
Result should be filtered for multiple input also.
So, how can i handle this multiple conditions in Query?
I’m confusing how to write query (in former way):
SELECT * FROM _item_ WHERE color='silver' AND/OR .... ... ?????
????
A simple sample please.
The easiest approach would be to have a base query, that even without filter criteria, still returns results:
this then allows you to easily add additional criteria to further filter your results, based on what was specified in the user interface. So, if someone says they want to filter on the color “silver” and the condition “new”, we just add these to the
WHEREclause of our query:each additional filter criteria can just be added with an
ANDto the end of the base query.edit: as pointed out in other posts, this is a naïve approach and you need to be careful of SQL injection, but the original question asked for a simple example and this was as simple as I could think of.