hiya!
can anyone tell me if there's anything obviously wrong with the following code (it is just basically intended to query my database, according to two variables - Area and Keywords - that the user will have typed into a form):
if ((!empty($area)) && (!empty($keywords)))
$query = "SELECT h.EstablishmentName,h.RoomsFrom,h.NumBedrooms,h.EstablishmentType,h.Address1,h.Address2,h.Town,h.County,h.DescriptionEnglish,h.LongDescriptionEnglish,h.Hotel_Id,h.Region,h.AARating,h.RACRating FROM hotel h LEFT JOIN amenities a ON h.Hotel_Id=a.Hotel_Id WHERE (MATCH ((h.Town,h.DescriptionEnglish,a.Amenities) AGAINST ('$keywords' IN BOOLEAN MODE))) AND (Town='$area' OR County='$area' OR Region='$area' OR Postcode='$area' OR GeoVillage='$area' OR GeoBorough='$area') ORDER BY $sortBy LIMIT $offset, $limit";
if ((!empty($area)) && (empty($keywords)))
$query = "SELECT EstablishmentName,RoomsFrom,NumBedrooms,EstablishmentType,Address1,Address2,Town,County,DescriptionEnglish,LongDescriptionEnglish,Hotel_Id,Region,AARating,RACRating FROM hotel WHERE Town='$area' OR County='$area' OR Region='$area' OR Postcode='$area' OR GeoVillage='$area' OR GeoBorough='$area' ORDER BY $sortBy LIMIT $offset, $limit";
if ((empty($area)) && (!empty($keywords)))
$query = "SELECT h.EstablishmentName,h.RoomsFrom,h.NumBedrooms,h.EstablishmentType,h.Address1,h.Address2,h.Town,h.County,h.DescriptionEnglish,h.LongDescriptionEnglish,h.Hotel_Id,h.Region,h.AARating,h.RACRating FROM hotel h LEFT JOIN amenities a ON h.Hotel_Id=a.Hotel_Id WHERE MATCH (h.Town,h.DescriptionEnglish,a.Amenities) AGAINST ('$keywords' IN BOOLEAN MODE) ORDER BY $sortBy LIMIT $offset, $limit";
if ((empty($area)) && (empty($keywords)))
$query = "";
$result = mysql_query($query)
or die ("Couldn't execute query");
I had it working before when I was testing it with Keywords only, but as soon as i've tried to add in all the if statements so that i could cover the Area searches as well, it's all a bit wrong!
I'm not exactly the world's expert on php querying though so would be grateful if someone can tell me where i might be going wrong!
Thanks very much!
LizzyD