Page 1 of 1

Calendar Whole Year

Posted: Mon Mar 05, 2007 4:35 pm
by aspekt9
I use a calendar script, Keith Deven's PHP Calendar. I've modified it to incorporate events into it and everything works great. The problem I'm having trouble with is when I print the year long calendar. For some reason it only reads the dates in the database for the current month, in this case March and it outputs the same days for every single month. I don't understand how I can fix this. The code displaying the year long calendar is:

Code: Select all

include 'calendarparent.php';
include 'config.php'; 
$today = date('j',$time);
$month = date('n');
$year = date('Y');
	$events = mysql_query("SELECT *, DATE_FORMAT(date, '%M %e, %Y %h:%m:%s') as
            date,  DATE_FORMAT(date, '%c') as month,  DATE_FORMAT(date, '%e') as day FROM calevents order by date desc") or die(mysql_error());
        if($events)
          {
          $days = array();
			while($row = mysql_fetch_array($events))
            {
                if($row['month'] == $month)
                {
					$day = $row['day'];
					$days[$day] = array('events.php?action=view&id='.$row['id'], 'linked-day');
                }
            }
        }	
		echo "<table style=\"margin: auto\"width=450>";
		echo "<tr>";
			for($month=1; $month<=12; $month++)
			{
				echo "<td style=\"vertical-align: top\">";
				echo parent_calendar($year, $month, $days,2); 
				echo "<br /></td>";
					if($month%3 == 0 and $month<12){
						echo "</tr><tr>";
					} 
			} 
echo "</tr>";
echo "</table>";
I think the problem is:

Code: Select all

echo parent_calendar($year, $month, $days,2);


Which makes sense because $days is retrieved from the database if it is equal to the current month, but how can I change this so each date prints to the correct month and day?

Posted: Mon Mar 05, 2007 9:01 pm
by Christopher
Instead of looping through your entire data set, it would be better to only SELECT record in the current month and year.