Hello,
Im new to this forum and also new to php/mysql. I am working on a RealEstate website and i need to create a search form for it which will search the database.
Below is the query which i am using.
if($_GET["city"] != ""){
$query_srch_rslts = sprintf("SELECT * FROM listings WHERE city = %s AND type = %s AND price BETWEEN %s AND bedrooms > %s AND bathrooms > %s AND pool = %s AND acreage = %s AND finished_basment = %s ORDER BY price DESC", $qcity,$qtype,$qprice,$qbedrooms,$qbathrooms,$qpool,$qacreage,$qbasement);
}
It works OK and returns the results as long as i give it a value for city .(i.e city = 1). I want to modify it so that it'll be able to return all the records for Any city.
I tried using ""(city = ) and empty " "... but it didnt work. so i wrote 2 queries for it.
if($_GET["city"] == ""){
$query_srch_rslts = sprintf("SELECT * FROM listings WHERE type = %s AND price BETWEEN %s AND bedrooms > %s AND bathrooms > %s AND pool = %s AND acreage = %s AND finished_basment = %s ORDER BY price DESC", $qtype,$qprice,$qbedrooms,$qbathrooms,$qpool,$qacreage,$qbasement);
}
But this is not the proper way. I know there has to be something in SQL.
It returns an Error when i use "*' and no result is found when i use empty " "
I'd greatly appreciate any Help.
Thanks