I have a calendar that I want to display a icon when there is an event booked on that date but the problem crazy thing isn't working. Here's my coding and i'll outline what I believe to be the problem with a ************.

Thanks,
Mike

<?PHP
session_start();
include ("dblib.inc");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<head>

<title>Calendar</title>
<Link href="arial.css" rel="stylesheet" title="arial" type="text/css">

</head>

<body>
<img src="pics/logo.gif">
<BR>
<div align="center"><font size="4">Calendar of Events</font> <BR>
<hr>
<BR>
<?PHP
mk_drawCalendar($m,$y);
?></div>

<div align="center">
<?PHP
// Draw the Calendar
function mk_drawCalendar($m,$y)
{
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="100%">
<tr>
<th width="100">
<a href="<?=$SCRIPT_NAME?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>">&lt;&lt;</a>
</th>
<th><font size=2><?="$month $y"?></font></th>
<th width="100">
<a href="<?=$SCRIPT_NAME?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>">&gt;&gt;</a>
</th>
</tr>
</table>
</td>
</tr>
<tr>
<th width=100 class="tcell">Sunday</th>
<th width=100 class="tcell">Monday</th>
<th width=100 class="tcell">Tuesday </th>
<th width=100 class="tcell">Wednesday</th>
<th width=100 class="tcell">Thursday</th>
<th width=100 class="tcell">Friday</th>
<th width=100 class="tcell">Saturday</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=100 bgcolor=#CCCCCC><font size=2>&nbsp;</font></th>"; }
        $firstweek = false;
    }

**********PROBLEM IS BETWEEN HERE *
$select = "SELECT
FROM activities, clientactivity WHERE CUserName='$CUserName'";
$result = mysql_query($select);
$numrows = mysql_num_rows($result);
******* AND HERE (I THINK) *********

	//checks for event
	if($numrows>=1)
		{
		//Event exists
        print "<td class='tcell' bgcolor=#CCCCCC valign=\"top\" height=\"100\">
		<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=\"100\">
		<a href=calendardetails.php?ADay=$d&AMonth=$themonth&AYear=$y target=\"new_window\"><B>$d</b></a>
		</td>";
		}

    //Saturday end week with <tr>

// if ($wday==6) { print "<th height=150 bgcolor=#00ff00></tr>\n</th>"; }

    $wday++;
    $wday = $wday % 7;
    $d++;

	// Sunday start week with <tr>
    if ($wday==0) { print "<th height=100 bgcolor=#ffffff><tr></th>"; }

	//blanks for last week
    if ($lastweek) {
        print "<tr>";
        for ($lastday=28; $tlastday<=31; $lastday++) 
        { print "<th height=100 bgcolor=#AAAAAA></th><font size=2>&nbsp;</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;
}
?>
</div>
</body>

    I am creating a calendar function too, somewhat like yours, noted that in your SQL statement you don't have any way to figure out what date range you are looking at (unless I missed it, it is early and I haven't had my coffee yet).

    Could that be the problem?

    The way I do it (at the suggestion of a few good folks on this list to minimize processor time) is to query my event database for a specific month, then run through the results once, assigning an element in an array a value of 1 if there is an event on a specific date. Of course, you must take into account date ranges, which means you have to look into events that bridge over multiple months as well.

    Contact me off line if you want to see the script.

    HTH

    Jim Hawley

      10 months later

      I have a similar calendar...and I am sorry that I do not know how to display an Icon either....

      Does anyone know how to make the calendar more printer friendly from a print calendar ("current month") link?

      Thanks.

        Write a Reply...