Alright, I would like some advice on how to code an advanced search for the profiles the right way.
The "advanced" search contains:
Gender female/both/male
Search in All/latest profiles 1/2/7/14/32 days ago
Online: Yes(checked)
Age (xx) to (xx) years (xx means you can write e.g 12 and 18)
Cities: all/city1/city2/city3
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:
$query = "SELECT * FROM users WHERE"
if(!empty($gender){ // if its empty, then the user chose both..
$query .= "gender = $gender";
}
....
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 ..