I'm having some HUGE problems that I desperately need a bit of help with. I have a calendar application. It's supposed to display "Activity" on a day that user has booked an activity. It works fine when they first bring up the calendar. However, when they move forward a month then back to the previous month. All the days that used to say "Activity" no longer have that word anymore. Why?
Below is my script:
<div align="center">
<?PHP
mk_drawCalendar($m,$y);
?></div>
<div align="center">
<?PHP
// Draw the Calendar
function mk_drawCalendar($m,$y)
{
global $CUserName, $PHP_SELF;
if ((!$m) || (!$y))
{
$m = date("m",mktime());
$y = date("Y",mktime());
if ($m==1)
$themonth="jan";
else if ($m==2)
$themonth="feb";
else if ($m==3)
$themonth="mar";
else if ($m==4)
$themonth="apr";
else if ($m==5)
$themonth="may";
else if ($m==6)
$themonth="jun";
else if ($m==7)
$themonth="jul";
else if ($m==8)
$themonth="aug";
else if ($m==9)
$themonth="sept";
else if ($m==10)
$themonth="oct";
else if ($m==11)
$themonth="nov";
else if ($m==12)
$themonth="dec";
}
// get what weekday the first is on /
$tmpd = getdate(mktime(0,0,0,$m,1,$y));
$month = $tmpd["month"];
$firstwday= $tmpd["wday"];
$lastday = mk_getLastDayofMonth($m,$y);
?>
<font size=1>Click on date to see details</font>
<table cellpadding=2 cellspacing=0 border=1>
<tr>
<td colspan=7 bgcolor="#cccc99">
<table cellpadding=0 cellspacing=0 border=0 width="455">
<tr>
<th width="65">
<a href="<?=$PHP_SELF?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>&CUserName=<?=$CUserName?>"><<</a>
</th>
<th><font size=2><?="$month $y"?></font></th>
<th width="65">
<a href="<?=$PHP_SELF?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>&CUserName=<?=$CUserName?>">>></a>
</th>
</tr>
</table>
</td>
</tr>
<tr>
<th width=65 class="tcell">Sun</th>
<th width=65 class="tcell">Mon</th>
<th width=65 class="tcell">Tues </th>
<th width=65 class="tcell">Wed</th>
<th width=65 class="tcell">Thur</th>
<th width=65 class="tcell">Fri</th>
<th width=65 class="tcell">Sat</th>
</tr>
<?PHP
$d = 1;
$wday = $firstwday;
$firstweek = true;
//Loop Through to last day
while ( $d <= $lastday)
{
//blanks for first week
if ($firstweek) {
print "<tr>";
for ($i=1; $i<=$firstwday; $i++)
{ print "<th height=65 bgcolor=#CCCCCC><font size=2> </font>
</th>"; }
$firstweek = false;
}
//checks for event
if($numrows>=1)
{
//Event exists
print "<td class='tcell' bgcolor=#CCCCCC valign=\"top\" height=\"65\">
<a href=calendardetails.php?ADay=$d&AMonth=$themonth&AYear=$y target=\"new_window\"><B>$d</b></a>
</td>";
}
else
{
//Event doesn't exist
print "<td class='tcell' bgcolor=#CCCCCC valign=\"top\" height=\"65\">
<a href=calendardetails.php?ADay=$d&AMonth=$themonth&AYear=$y target=\"new_window\"><B>$d</b></a>";
//Print "Activity" if there is an event booked.
$eventrows = 0;
$query = "SELECT * FROM clientactivity WHERE CUserName='$CUserName' AND ADay='$d' AND AMonth='$themonth' AND AYear='$y'";
$result = mysql_query($query);
$eventrows = mysql_num_rows($result);
if($eventrows>0)
print "<BR>Activity";
print "</td>";
}
$wday++;
$wday = $wday % 7;
$d++;
// Sunday start week with <tr>
if ($wday==0) { print "<th height=65 bgcolor=#ffffff><tr></th>"; }
//blanks for last week
if ($lastweek) {
print "<tr>";
for ($lastday=28; $tlastday<=31; $lastday++)
{
print "<th height=65 bgcolor=#AAAAAA>
</th><font size=2> </font>"; }
$lastweek = false;
}
}
?>
</tr></table>
<font size=1>Click on date to see details</font>
<br>
<?PHP
//end calendar Draw Function
}
//Show the last day of the month
function mk_getLastDayofMonth($mon,$year)
{
for ($tday=28; $tday <= 31; $tday++)
{
$tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
if ($tdate["mon"] != $mon)
{ break; }
}
$tday--;
return $tday;
}
?>
</td>
</tr>
</table>
<table width="640" border="0">
<TR>
<TD align="center">
<Font size="-1">
For the best viewing experience and use of all functionality,<BR>
we recommend using <a href="http://www.microsoft.com/windows/ie/download/" target="new_window">Microsoft Internet Explorer 5.0</a> or greater.
</font>
</td>
</tr>
</table>
<?PHP
mysql_close();
?>
</body>