Hi all,
My script works fine until we add two reservations for the same apartment with different dates.
It outputs a list of all available apartments from dates selected in a form.
I have two tables
Apartments and reservations
It should select all the apartments in our database then check the reservations table and output only those are not between the from date and to date.
I think the select process may be correct and we have something else missing in the rest of the script.
Please post any thoughts or ideas
Thanks
Here is my code
$sql = "SELECT apartments.* FROM apartments LEFT JOIN reservations ON reservations.ID=apartments.ID WHERE
('$start' NOT BETWEEN reservations.fromdate AND reservations.todate AND '$end' NOT BETWEEN reservations.fromdate AND reservations.todate AND
reservations.fromdate NOT BETWEEN '$start' AND '$end' AND
reservations.todate NOT BETWEEN '$start' AND '$end' OR reservations.ID IS NULL)
AND apartments.size IN($rooms)";
$result = mysql_query($sql)
or die("could not find id in the table or check the dates");
$num = mysql_num_rows($result);
$nrows = mysql_num_rows($result);
include ('template.php');
echo "<strong><span class='text'><br><br> We have the following apartments available<br><br></span></strong>";
echo"<table border='1' cellspacing='0' cellpadding='3'>";
for ($i=0;$i<$nrows;$i++)
{
$n = $i + 1;
$row = mysql_fetch_array($result);
extract($row);
echo"<tr>\n
<td>$id</td>\n
<td>$type</td>\n
<td>$location</td>\n
<td><a href='$url' class='linkmenu'>$description</a></td>\n
</tr>\n<tr><td></td>";
}