I'm making a search engine for my website. I have six select
fields: price, number of doors, transmisson, fuel type, engine type and co2 emission.
I want to let the user of the search engine search as detailed as possible. So, if he only selects price and transmission, then there must be searched for price and transmission, etc. If he searches for price, number of doors and engine type, then there must be searched for those 3 parameters.
So I figured that there are 6^6 = 46 656 different combinations. Thats too much for if'ing and else'ing ..
If the user does not select anything, the returned value of the select
field will be "empty"
.
Also important to note is that price is always set (minimum is 0 and maximum is 100 000).
There must be a way to combine all those things into one query, right? That would make my life a lot easier :).
Could you explain the way (if there's actually one) to do that?
6^6 = 46 656 I dont think, you are gonna be doing that much if and else
Lets say you get the search parameters from POST
$sql = "select * from table_name where 1=1";
if(isset($_POST['price']))
$sql .= " AND price='".$_POST['price']."'";
if(isset($_POST['numdoors']))
$sql .= " AND numdoors = '".$_POST['numdoors']."'";
//and so on......
So you have 6 if
s