hello,
I am asked to develop a calender for online theater booking.
in which each date has 3 time slots and if any booking is done in that date and time slot that field should have red background means that time slot for that date is booked.
other 2 slots should be in green background.
please help me in this regards.
I am developing in php and mysql.
below is my code for calender:
<?php
error_reporting(0);
function build_calendar($month,$year,$dateArray) {
$daysOfWeek = array('S','M','T','W','T','F','S');
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
$numberDays = date('t',$firstDayOfMonth);
$dateComponents = getdate($firstDayOfMonth);
$monthName = $dateComponents['month'];
$dayOfWeek = $dateComponents['wday'];
$calendar = "<table class='calendar' border=1>";
$calendar .= "<caption>$monthName $year</caption>";
$calendar .= "<tr>";
foreach($daysOfWeek as $day) {
$calendar .= "<th class='header'>$day</th>";
}
$currentDay = 1;
$calendar .= "</tr><tr>";
if ($dayOfWeek > 0) {
$calendar .= "<td colspan='$dayOfWeek'> </td>";
}
$month = str_pad($month, 2, "0", STR_PAD_LEFT);
while ($currentDay <= $numberDays) {
if ($dayOfWeek == 7) {
$dayOfWeek = 0;
$calendar .= "</tr><tr>";
}
$currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT);
$date = "$year-$month-$currentDayRel";
$calendar .= "<td class='day' rel='$date'>$currentDay
<table border=1>
<tr><td bgcolor='green'>10am-1pm</td></tr>
<tr><td bgcolor='yellow'>1.30pm-4.30pm</td></tr>
<tr><td bgcolor='green'>5pm-8pm</td></tr>
</table>
</td>";
$currentDay++;
$dayOfWeek++;
}
if ($dayOfWeek != 7) {
$remainingDays = 7 - $dayOfWeek;
$calendar .= "<td colspan='$remainingDays'> </td>";
}
$calendar .= "</tr>";
$calendar .= "</table>";
return $calendar;
}
$dateComponents = getdate();
$month = $dateComponents['mon'];
$year = $dateComponents['year'];
echo build_calendar($month,$year,$dateArray);
?>