PHP: Coding “advanced search” the best way

indiamafia

New Member
Alright, I would like some advice on how to code an advanced search for the profiles the right way.The "advanced" search contains:\[code\]Gender female/both/maleSearch in All/latest profiles 1/2/7/14/32 days agoOnline: Yes(checked)Age (xx) to (xx) years (xx means you can write e.g 12 and 18)Cities: all/city1/city2/city3\[/code\]There's a lot of criteria that you can pick and choose. I would like to know how should I code this the most effective way, with the least code repetition. Should I build a query from what the user chooses? Example:\[code\]$query = "SELECT * FROM users WHERE"if(!empty($gender){ // if its empty, then the user chose both.. $query .= "gender = $gender";}....\[/code\]Or are there any better solutions? I think doing this will result in problems, because if an user doesn't choose any gender, and another if $online (example) starts with AND , it will result WHERE AND ..
 
Back
Top