I'm developing a Real Estate Classifieds, so I need to filter some fields if the user wants them, such as: Number of rooms, Number of parking spaces, Number of bathrooms, etc.
I need Query to have IF so I can validate if the variables are filled can filter the X or Y field or both.
Example:
SELECT type, property_type, city, region, neighborhood, price, rooms,
bathrooms, parking, content, img1, urlimovel, logo, url
FROM imoveis where type = '$oquedeseja' AND goal = '$idfinalidade'
AND property_type = '$idtipo' AND region = '$iduf' AND city = '$idcidade'
AND rooms = '$nquartos'
AND rooms = '$ nquartos'
In the above example it would check if the variable $ nquartos is not empty it would filter by rooms .