Hi,
I have a page that lists propertys for sale. I have built a search system that seraches on four different values.
bedrooms, property type, min price and max price.
I've got a bunch of if statements that build up the query depending on what search boxes have been used. Is there a way to do it with less code??
Please help...
if ($beds) { $search_query = "beds='$beds'"; }
else { $search_query = ""; }
if (!$search_query and $prop_type1) { $search_query = "prop_type='$prop_type1'"; }
elseif ($search_query and $prop_type1) { $search_query = "$search_query and prop_type='$prop_type1'"; }
else { $search_query = $search_query; }
if (!$search_query and $min_price) { $search_query = "price_ster>='$min_price'"; }
elseif ($search_query and $min_price) { $search_query = "$search_query and price_ster>='$min_price'"; }
else { $search_query = $search_query; }
if (!$search_query and $max_price) { $search_query = "price_ster<='$max_price'"; }
elseif ($search_query and $max_price) { $search_query = "$search_query and price_ster<='$max_price'"; }
else { $search_query = $search_query; }
if ($search_query) { $query = "select from property where $search_query order by price_ster asc $limit_str"; }
else { $query = "select from property order by price_ster asc $limit_str"; }