How to get calendar days as links

Hey,

I am trying to figure out how to get the days in the calendar on this page as links.

I am using the following code:


		 <?
	function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()){
    $first_of_month = gmmktime(0,0,0,$month,1,$year);

    $day_names = array(); #generate all the day names according to the current locale
    for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
        $day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name

    list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
    $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
    $title   = htmlentities(ucfirst($month_name)).'&nbsp;'.$year;  #note that some locales don't capitalize month and day names

    @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
    if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span>&nbsp;';
    if($n) $n = '&nbsp;<span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
    $calendar = '<table class="right">'."\
".
        '<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\
<tr>";

    if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
        #if day_name_length is >3, the full name of the day will be printed
        foreach($day_names as $d)
            $calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
        $calendar .= "</tr>\
<tr>";
    }

    if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'">&nbsp;</td>'; #initial 'empty' days
    for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
        if($weekday == 7){
            $weekday   = 0; #start a new week
            $calendar .= "</tr>\
<tr>";
        }
        if(isset($days[$day]) and is_array($days[$day])){
            @list($link, $classes, $content) = $days[$day];
            if(is_null($content))  $content  = $day;
            $calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
                ($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
        else $calendar .= "<td>$day</td>";
    }
    if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'">&nbsp;</td>'; #remaining "empty" days

    return $calendar."</tr>\
</table>\
";
}
?> 
<?php
    $time = time();
    echo generate_calendar(date('Y', $time), date('n', $time));
?>

I know it’s messy so apologies in advance. I simple need to be able to click on a day and send it to a page like so:

courses/?date=5 May 2010

Any ideas how i can do this? Otherwise are there any better methods i can use?

Thanks again

Ok, please ignore my 2 previous emails.

I have taken a different approach and have followed a tutorial, and have managed to create a calendar. You can see this here:

http://www.glofamily.com/glo/

If you try clicking on a day it will show the date. However the final thing i need to do is have a next/prev link which can flip through months.

This is my code so far:


		 <div id="calendar" class="right">
		<?php 
			$date = time () ;
			
			$day = date('d', $date) ;
			$month = date('m', $date) ;
			$year = date('Y', $date) ;
			
			$first_day = mktime(0,0,0,$month, 1, $year) ;
			$title = date('F', $first_day) ; 
			$day_of_week = date('D', $first_day) ; 
			
			switch($day_of_week){ 
				case "Sun": $blank = 0; break; 
				case "Mon": $blank = 1; break; 
				case "Tue": $blank = 2; break; 
				case "Wed": $blank = 3; break; 
				case "Thu": $blank = 4; break; 
				case "Fri": $blank = 5; break; 
				case "Sat": $blank = 6; break; 
			}
			
			$days_in_month = cal_days_in_month(0, $month, $year) ; 
		?>
		 
		 <div id="php-calendar">
		 <table>
		 <tr><th colspan='7'><? echo $title. " ".$year; ?></th></tr>
		 <tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td></tr>
			
		<?
		 $day_count = 1;
		
		 echo "<tr>";
		 
		 while ( $blank > 0 ) 
		 { 
			 echo "<td></td>"; 
			 $blank = $blank-1; 
			 $day_count++;
		 } 
		 
		 $day_num = 1;
		 
		 while ( $day_num <= $days_in_month ) 
		 { 
			 echo "<td> <a href='general-courses/?day=$day_num $title $year'>$day_num</a></td>"; 
			 $day_num++; 
			 $day_count++;
		
			 if ($day_count > 7)
			 {
			 echo "</tr><tr>";
			 $day_count = 1;
			 }
		 } 
		 
		 while ( $day_count >1 && $day_count <=7 ) 
		 { 
		 echo "<td> </td>"; 
		 $day_count++; 
		 } 
		 ?> 

		</table>		
		</div> 

Can anyone help me with this?

Thanks again

Or can i not just use something like this:

http://jqueryui.com/demos/datepicker/#inline

And then customize it to link to a page?