I'm making a calendar system where the user makes bookings (on a different page). On this page, the user clicks the relevant box to choose a start time for the new booking. I'm checking the database for existing bookings and making those unclickable to prevent double booking.
My question is, why is only the first booking for that day appearing on the table?
Is the variable $booked
remaining true, and so not showing the other bookings? I can't get my head around it!
MySQL:
$query="SELECT * FROM bookings WHERE DateBooked = '{$year}-{$month}-{$selectedday}' AND Approved = 1";
$result = mysql_query($query);
$todayarray = mysql_fetch_assoc($result);
And PHP:
while ($room <= $roomcount) {
echo "\n<div class=\"roomtimes\">";
echo "\n<table border=1>";
echo "\n<tr><th class=\"titlecell\">Room $room</th></tr>";
$cellnum = 10;
while ($cellnum <= 22) {
if (($todayarray['StartTime'] <= $cellnum) && ($todayarray['EndTime'] >= $cellnum) && ($todayarray['Room'] == $room)) {
$booked = true;
} else {
$booked = false;
}
echo "\n<tr>";
if ($booked) {
echo "\n<td class=\"blankcell";
} else {
echo "\n<td class=\"linkcell";
}
if ($selectedtime == $cellnum) {
echo " selectedcell";
}
echo "\">";
if ($booked) {
echo "$cellnum:00 --BOOKED--";
} else {
echo "<a href=\"newbooking.php?m=$selectedmonth&d=$selectedday&t=$cellnum&r=$room\">$cellnum:00</a>";
}
echo "</td>";
echo "\n</tr>";
$cellnum++;
}
$room++;
echo "\n</table>";
echo "\n</div>";
}
echo "\n</div>";
?>