Forum Moderators: coopster
When I test the sql through Macromedia recordset test it works fine. The sql also works when I try to query the database directly on the host. However, when I load up the code and run it through the webpage it fails and does not return any values.
This behaviour occurs when I use 'AND' in my queries. It works on Macromedia database test but fails when run through the actual webpage. However, when I replace the 'AND' with 'OR' the query works through the webpage as well.
I have no idea why it works with 'OR' but not when I use 'AND', and also why Macromedia results are different to when I load it up on the webpage.
The code is below.
mysql_select_db($database_search_connection, $search_connection);
$query_Prop_Search = sprintf("SELECT Emirate, Length, Location, Beds, Furnishing FROM `property list`WHERE Emirate LIKE '%s' OR Length LIKE '%s' AND Location LIKE '%s' AND Beds LIKE '%s' AND Furnishing LIKE '%s'", $varEmirate_Prop_Search,$varLengthofstay_Prop_Search,$varLocation_Prop_Search,$varNoofbeds_Prop_Search,$varFurnishing_Prop_Search);
$query_limit_Prop_Search = sprintf("%s LIMIT %d, %d", $query_Prop_Search, $startRow_Prop_Search, $maxRows_Prop_Search);
$Prop_Search = mysql_query($query_limit_Prop_Search, $search_connection) or die(mysql_error());
$row_Prop_Search = mysql_fetch_assoc($Prop_Search);
$query_Prop_Search = sprintf("SELECT Emirate, Length, Location, Beds, Furnishing FROM `property list` WHERE (Emirate LIKE '%s' OR Length LIKE '%s') AND Location LIKE '%s' AND Beds LIKE '%s' AND Furnishing LIKE '%s'", $varEmirate_Prop_Search,$varLengthofstay_Prop_Search,$varLocation_Prop_Search,$varNoofbeds_Prop_Search,$varFurnishing_Prop_Search);
Note the (,) in the OR statements