Hello- can anyone tell me why this function does not create links on the calendar from my recordset. I know that the recordset is filling the array but it still will not output the links in the if/else clause.
<?php
function build_calendar($month,$year,$day) {
/* Declaring the variables */
$daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa');
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
$noDays = date('t',$firstDayOfMonth);
$dateComponents = getdate($firstDayOfMonth);
$dayOfWeek = $dateComponents['wday'];
$monthName = date('F',mktime(0,0,0,$month,1,$year));
global $getEvtDates; //this is the name of the recordset
global $_GET;
if (mysql_num_rows($getEvtDates) > 0) {
mysql_data_seek($getEvtDates,0);
while ($row_getEvtDates = mysql_fetch_assoc($getEvtDates)) {
$dates[] = $row_getEvtDates['event_date'];
}
}
/* Computing the previous month. */
if($month == 1) {
$mn=12;
$yn=$year-1;
} else {
$mn=$month-1;
$yn=$year;
}
/* Computing the next month. */
if($month == 12) {
$mn2=1;
$yn2=$year+1;
} else {
$mn2=$month+1;
$yn2=$year;
}
/* Calendar header: next and previous month links */
$calendar = "<table>";
$calendar .= "<tr><td><p><a href=get_days_events.php?y=$yn&m=$mn&d=$day><</a></p></td>";
$calendar .="<td colspan=5 align=center><p><strong>$monthName, $year</strong></p></td>";
$calendar .="<td><p><a href=get_days_events.php?y=$yn2&m=$mn2&d=$day>></a></p></td></tr>";
$calendar .="<tr>";
/* Calendar header: Display the days of the week */
foreach($daysOfWeek as $day) {
$calendar .= "<td><p>$day</p></td>";
}
$calendar .= "</tr>";
$calendar .= "<tr>";
$currentDay = 1;
/* Fill in the beginning of the calendar body */
if ($dayOfWeek > 0) {
$calendar .= "<td colspan='$dayOfWeek'> </td>";
}
/* Generate the calendar body */
while ($currentDay <= $noDays) {
if ($dayOfWeek == 7) {
$dayOfWeek = 0;
$calendar .= "</tr><tr>";
}
$date = $year."-".$month."-".$currentDay; //here's where the trouble might start
if (in_array($date,$dates)) {
$calendar .= "<td><p><a href='get_days_events.php?y=$year&m=$month&d=$currentDay'>$currentDay</a></p></td>";
} else {
$calendar .= "<td><p>$currentDay</p></td>";
}
$currentDay++;
$dayOfWeek++;
}
/* Filling in the end of the calendar body */
if ($dayOfWeek != 7) {
$remainingDays = 7 - $dayOfWeek;
$calendar .= "<td colspan='$remainingDays'> </td>";
}
$calendar .= "</table>";
return $calendar;
}
if (isset($_GET['m']) && isset($_GET['y']) && isset($_GET['d'])){
$month = $_GET['m'];
$year = $_GET['y'];
$day = $_GET['d'];
} else {
$dateComponents = getdate();
$month = $dateComponents['mon'];
$year = $dateComponents['year'];
$day = $dateComponents['mday'];
}
echo build_calendar($month,$year,$day);
?>