Calendar Whole Year

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aspekt9
Forum Commoner
Posts: 43
Joined: Wed Dec 06, 2006 5:03 pm

Calendar Whole Year

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Instead of looping through your entire data set, it would be better to only SELECT record in the current month and year.
(#10850)
Post Reply