I have a table with info on Hotels, a table with Amenities that a Hotel may have and a table linking both together.
I want my script to show me all the Hotels that have a variable number of amenities that have been selected by a client.
My scrpit so far, works in that I can get a lsit, as requested, but only if a client chooses ONE amenity. If client chooses more than one, I get a Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.
My code will also give me the above result if I add the "OR" to get more than one amenity.
Can anybody help me write the script correctly?.
My script so far, is as follows :
I can get a lsit of all the Hotels that have one chosen amenity, but I cannot get a list of all the hotels that have more than one amenity?
stories is a table with Hotel details
amenities is a table of amenities
lookup_amenities is a table to link both tables
if (!empty($amenities)) {
//<!-- Lists the Hotel that has the amenities -->
$query ="select distinct stories.headline, lookup_amenities.amenity_id, amenities.name
from lookup_amenities, amenities, stories
where lookup_amenities.hotel_id=stories.id
and lookup_amenities.amenity_id= amenities.id
";
$query .= "and (";
foreach ($amenities as $check){
$query .= " lookup_amenities.amenity_id = $check ";
// PROBLEM LINE, that is not accepted --->$query .= " or";
}
$query .=")";
$count = count ($amenities);
// PROBLEM LINE, that is not accepted --->$query .= "group by stories.headline having count (stories.headline) >= $count";
$query .= ";";
}
/ execute the query/
$result = mysql_query($query);
/ each row in the result set will be packaged as an object and put in an array/
while($row = mysql_fetch_array($result)) {
array_push($checked_arr, $row);
echo " ", $row['headline'], " is the Hotel Name<br>",
$row['name'], " is the Amenity Name<br>",
$row['amenity_id'], " is the Amenity Id<br><br>";
}
Thanks in anticipation!!