I'm afraid I wasn't able to get that to work. I think it has something to do with the $a_row variable not knowing what the current date is. I think we need to have a variable that is fed with $eventdate, $eventid (for the hyperlink) and $eventname. Maybe an associative array organized by date. This prints out the elements of the array, but I don't know how to make this an array that anything can access:
$cal_sql = mysql_query( "SELECT eventdate, eventid, eventname FROM calendar WHERE clientid='$id'" );
while ($cal_row = mysql_fetch_assoc($cal_sql)) {
echo $cal_row["eventdate"]."<br>";
echo $cal_row["eventid"]."<br>";
echo $cal_row["eventname"]."<br>";
}
Then, each day needs to check itself against that array to see if it is a date that is matched in the array. The main problem I see here is that in the meat of the day printing, the code only knows the day of the month - I don't think it knows $month and $year and therefor doesn't see a match in the array. Here's the calendar function in its entirety. Any input is appreciated.
cheers,
Jason
<?php
function pc_calendar( $month, $year, $opts = '', $cal_row ) {
foreach ( $cal_row as $key => $val ) {
print "$key = $val<br>";
}
//set default options
if ( ! is_array( $opts ) ) {
$opts = array();
}
if ( ! isset( $opts['today_color'] ) ) {
$opts['today_color'] = '#FFFF00';
}
if ( ! isset( $opts['month_link'] ) ) {
$opts['month_link'] = '<a href="'.$_SERVER['PHP_SELF'].'?month=%d&year=%d">%s</a>';
}
list( $this_month, $this_year, $this_day ) = split( ',', strftime( '%m, %Y, %d' ) );
$day_highlight = ( ( $this_month == $month ) && ( $this_year == $year ) );
list( $prev_month, $prev_year ) = split( ',', strftime( '%m, %Y', mktime( 0, 0, 0, $month - 1, 1, $year ) ) );
$prev_month_link = sprintf( $opts['month_link'], $prev_month, $prev_year, '<');
list( $next_month, $next_year ) = split( ',', strftime( '%m, %Y', mktime( 0, 0, 0, $month + 1, 1, $year ) ) );
$next_month_link = sprintf( $opts['month_link'], $next_month, $next_year, '>');
?>
<table bordercolordark="#000000" cellpadding="2" cellspacing="0" width="95%" border="1" align="center">
<tr>
<td align="center" colspan="7" height="35">
<?php
print $prev_month_link." <h3> ".strftime( '%B, %Y', mktime( 0, 0, 0, $month, 1, $year ) )." </h3> ".$next_month_link ;
?>
</td>
</tr>
<?php
$totaldays = date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
//print out days of the week
print '<tr>';
$weekdays = array( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' );
while ( list( $k, $v ) = each( $weekdays ) ) {
print '<td align="center">'.$v.'</td>';
}
print '</tr><tr>';
//align the first day of the month with the right weekday
$day_offset = date( "w", mktime( 0, 0, 0, $month, 1, $year ) );
if ( $day_offset > 0 ) {
for ( $i = 0; $i < $day_offset; $i++ ) {
print '<td valign="top" width="14%" > </td>';
}
}
$yesterday = time() - 86400;
//print out the days
for ( $day = 1; $day <= $totaldays; $day++ ) {
$day_secs = mktime( 0, 0, 0, $month, $day, $year );
if ( $day_secs >= $yesterday ) {
if ( $day_highlight && ( $day == $this_day ) ) {
print sprintf( '<td valign="top" align="right" width="100" height="100" bgcolor="%s">%d<br><hr></td>', $opts['today_color'], $day );
} else {
print sprintf( '<td valign="top" align="right" width="100" height="100" >%d<br><hr></td>', $day );
}
} else {
print sprintf( '<td valign="top" align="right" width="100" height="100" >%d<br><hr></td>', $day );
}
$day_offset++;
//start a new blank row
if ( $day_offset == 7 ) {
$day_offset = 0;
print "</tr>\n";
if ( $day < $totaldays ) {
print "<tr>";
}
}
}
//fill in the last week with blanks
if ( $day_offset > 0 ) {
$day_offset = 7 - $day_offset;
}
if ( $day_offset > 0 ) {
for ( $i = 0; $i < $day_offset; $i++ ) {
print "<td> </td>";
}
}
print "</tr></table>";
}
?>