hi
i currently have a query that looks like the below (only there are a total of 16 else if's!) i know it is a horrible way to code it but i am new to this and as a starting point it did what i wanted it too.
if (($location !== any) && ($type !== any)) {
$result = mysql_query("SELECT * FROM table WHERE price_id='".$price_id."' AND location='".$location."' AND type='".$type."'") or die (mysql_error());
} else if (($location == any) && ($type !== any)) {
$result = mysql_query("SELECT * FROM table WHERE price_id='".$price_id."' AND type='".$type."'") or die (mysql_error());
} else if (($location !== any) && ($type == any)) {
$result = mysql_query("SELECT * FROM table WHERE price_id='".$price_id."' AND location='".$location."'") or die (mysql_error());
} else if (($location == any) && ($type == any)) {
$result = mysql_query("SELECT * FROM table WHERE price_id='".$price_id."'") or die (mysql_error());
}
bastien kindly showed some code that seemed to suggest i could do it something like the below. can someone check my syntax please, it doesn't seem to work but it looks as though it should be possible. many thanks!
$result = "SELECT * FROM table WHERE price_id='".$price_id."'";
if ($location !== any){
$result_where .= " AND location='".$location."' ";
}
if ($type !== any){
$result_where .= " AND type='".$type."' ";
}