As r937 has mentioned the WHERE filters the results returned. There are two posibilities:
1. Dynamically generating the where clause using something like:
Code:
$sql = "SELECT table1.id, table1.price, table1.beds, table1.type FROM table1";
$where = "";
if(isset($minprice) && $minprice >= 0) {
$where .= ($where == "")? " (table1.price >= $minprice)": " and (table1.price >= $minprice)";
}
if(isset($maxprice) && $maxprice >= 0) {
$where .= ($where == "")? "(table1.price <= $maxprice)": " and (table1.price <= $maxprice)";
}
if(isset($beds) && $beds > 0) {
$where .= ($where == "")? "(table1.beds <= $bedrooms)": " and (table1.beds <= $bedrooms)";
}
if(isset($type) && $type != "") {
$where .= ($where == "")? "(table1.type = '$prototype')": " and (table1.type = '$prototype')";
}
$sql .= (($where == "")?"":" WHERE" . $where);
or
2. Write the SQL as follows:
I am assuming that all the PHP variables are set to "" if no value has been added.
Code:
$sql =
"SELECT table1.id, table1.price, table1.beds, table1.type
FROM table1 WHERE
('$minprice' = '' or table1.price >= $minprice) AND
('$maxprice' = '' or table1.price <= $maxprice) AND
('$bedrooms' = '' or table1.beds >= $bedrooms) AND
('$prototype' = 'Show all properties' or table1.type = '$proptype')";