0
I have a form with all the districts of portugal. When I select a city I do the search through the method post, get the value city and research shows everything that exists with the city countryside. So far so good.
But when the value city is equal to ALL or (all), as I can say in the query that the user wants to see all cities?
Receiving the values of the form:
$localidade=$_REQUEST['localidade'];
$genero=$_REQUEST['genero'];
$idade_1=$_REQUEST['age-min'];
$idade_2=$_REQUEST['age-max'];
Consultation:
$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 the form values:
$consulta="local='$localidade' AND";
}else{$consulta="";}
$genero=$_REQUEST['genero'];
$idade_1=$_REQUEST['age-min'];
$idade_2=$_REQUEST['age-max'];
Consultation:
$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;
";
Delete the part
local='$localidade' ANDof the WHERE clause– ramaral
Or create 2 querys, one for when filtering cities and another to bring all.
– user28595
what do you think of the solution I’ve found?
– David Concha
If it works, it looks like OK!. I don’t know anything about php! :(
– ramaral
In this code, the first block, is where I take the values of
inputform fields. In the second block is where I query the database according to the values I picked from the form– David Concha