I have a form with all the districts of portugal. When I select a city, I search using the post
method, I get the value
of the city and the search shows everything that exists with the city field. So far so good.
But when the value
of the city is equal to ALL or (all), how can I say in the query that the user wants to see all cities?
Receiving form values:
$localidade=$_REQUEST['localidade'];
$genero=$_REQUEST['genero'];
$idade_1=$_REQUEST['age-min'];
$idade_2=$_REQUEST['age-max'];
Inquiry:
$sql = "SELECT u.id, u.username, u.genero, u.idade, u.local, u.descricao, u.status,u.last_login, u.photo_p_id, p.location
FROM user AS u
LEFT JOIN photos AS p
ON u.photo_p_id=p.id
WHERE local='$localidade' AND genero ='$genero' AND idade BETWEEN '$idade_1' and '$idade_2'
LIMIT 5;
";
What do you think of my solution?
Receiving form values:
$consulta="local='$localidade' AND";
}else{$consulta="";}
$genero=$_REQUEST['genero'];
$idade_1=$_REQUEST['age-min'];
$idade_2=$_REQUEST['age-max'];
Inquiry:
$sql = "SELECT u.id, u.username, u.genero, u.idade, u.local, u.descricao, u.status,u.last_login, u.photo_p_id, p.location
FROM user AS u
LEFT JOIN photos AS p
ON u.photo_p_id=p.id
WHERE $consulta genero ='$genero' AND idade BETWEEN '$idade_1' and '$idade_2'
LIMIT 5;
";