0

Hi

I have a search function where the user selects from drop down boxes.

There are 4 fields to choose from and any of the 15 combinations can be used to search with.

I am using Else If and the very first IF works, but when it is false it doesnt move on to the next condition.

Here is part of my code as the rest is very similar:

<?

   if ("'".$_POST['type_id']."' =='' and '".$_POST['location_id']."' >'0' and '".$_POST['bedroom_id']."' >'0' and '".$_POST['price_id']."' >'0' ")
  {
    $Select = "Select * from homes, type, bedrooms, prices, area where homes.type_id = type.id and homes.bedroom_id = bedrooms.id and 
               homes.location_id = area.id and homes.price_id = prices.id and rented <> 0 and bedroom_id = '".$_POST['bedroom_id']."' 
               and location_id = '".$_POST['location_id']."' and price_id = '".$_POST['price_id']."' order by price desc";     
$Homes = mysql_query($Select);
  }

else if 
("'".$_POST['bedroom_id']."' =='' and '".$_POST['location_id']."' >'0' and '".$_POST['type_id']."' >'0' and '".$_POST['price_id']."' >'0' ")

  {
  $Select = "Select * from homes, type, bedrooms, prices, area where homes.type_id = type.id and homes.bedroom_id = bedrooms.id and 
               homes.location_id = area.id and homes.price_id = prices.id and rented <> 0 and type_id = '".$_POST['type_id']."' 
               and location_id = '".$_POST['location_id']."' and price_id = '".$_POST['price_id']."' order by price desc";
$Homes = mysql_query($Select);
  }
else
  {
  $Select = "Select * from homes, type, bedrooms, prices, area where homes.type_id = type.id and homes.bedroom_id = bedrooms.id 
             and homes.location_id = area.id and homes.price_id = prices.id and rented <> 0 order by price desc";
$Homes = mysql_query($Select);
  }

?>

Where have I gone wrong?

Thanks in advance

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by cereal
2

Why all those quotes? Rewrite your statements:

if($_POST['type_id'] == FALSE && $_POST['location_id'] > 0 && $_POST['bedroom_id'] > 0 && $_POST['price_id'] > 0)
Votes + Comments
Thanks for showing me a better way to write this code
0

Why all those quotes?

Hi, I am still learning and wasn't sure how to write it

Rewrite your statements:

if($_POST['type_id'] == FALSE && $_POST['location_id'] > 0 && $_POST['bedroom_id'] > 0 && $_POST['price_id'] > 0)

This now works perfectly and thanks for showing me a better way to write the code :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.