HI I am running PHP 4.4 and MySQL 5.0.x.
I have built a function that outputs an HTML calendar. The page gets a recordset of dates which then are put into an array making dates on the calendar links. For some reason, the dates that have records do not become links and I was wondering if anyone can help me find my error. I've pasted my code in below. Any help would really, really be appreciated.
php: [CODE]<?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;
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?m=$mn&y=$yn&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?m=$mn2&y=$yn2&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;
if (in_array($date, $Dates)) {
$calendar .= "<td><p><a href='get_days_events.php?m=$month&y=$year$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);
?>
[/CODE]
I know my recordset is funtioning correctly, but am fairly new to PHP. THANKS!!