I have tried to create the following query but it just doesn't seem to work when I select more than 1 option???
<?php
$locations = ($_GET['locations']);
$bedrooms = ($_GET['bedrooms']);
$dbcnx = @mysql_connect ("localhost", "root", "sj198024");
if (!$dbcnx) {
echo "Sorry your database connection has failed";
exit;
}
if (!@mysql_select_db("tpvhc", $dbcnx) ) {
echo( "<P>Unable to locate the Correct database at this time.</P>" );
exit();
}
foreach ( $locations as $lk => $lv ) {
$strquery .= ' Cottage.Location_ID = ' . $lv. ' OR ';
}
$strquery = substr($strquery, 0, -4); //remove the last 4 char - the last OR
$query = "SELECT Cottage.Cottage_ID, Cottage.Location_ID, Location.Location_ID, Location.Location, Cottage.Bedrooms FROM Cottage INNER JOIN Location ON Cottage.Location_ID = Location.Location_ID WHERE " . $strquery . " AND Cottage.Bedrooms = '$bedrooms'";
echo $query;
$result = mysql_query($query);
echo '<table class="table">';
echo '<tr><th>Cottage ID</th><th>Cottage Name</th><th>Cottage Name</th></tr>';
while($row = mysql_fetch_assoc($result)){
echo '<tr>';
echo '<td>' . $row['Cottage_ID'] . '</td>';
echo '<td>' . $row['Location'] . '</td>';
echo '<td>' . $row['Bedrooms'] . '</td>';
echo '</tr>';
}
echo '</table>';
?>
This is the query written to the page
SELECT Cottage.Cottage_ID, Cottage.Location_ID, Location.Location_ID, Location.Location, Cottage.Bedrooms FROM Cottage INNER JOIN Location ON Cottage.Location_ID = Location.Location_ID WHERE Cottage.Location_ID = 1 OR Cottage.Location_ID = 3 AND Cottage.Bedrooms = '4'
So as you can see it seems to of worked fine but it doesn't actually only return results where bedrooms = 4 it ignores this part. But if i only select 1 location the bedrooms bit works.
So I am thinking I need to do something to my query but I have no idea what.
Cheers