I cannot get the Previous/Next month selections to work correctly for a calendar I have built in PHP. Here is the coding for that portion of the calendar:
[code]/* date settings */
$month = (int) ($_POST[‘month’] ? $_POST[‘month’]
: ($_GET[‘month’] ? $_GET[‘month’]
: date(‘m’)));
$year= (int) ($_POST[‘year’] ? $_POST[‘year’]
: ($_GET[‘year’] ? $_GET[‘year’]
: date(‘Y’)));
/* “previous month” control */
$previous_month_link = ‘<< Previous Month’;
/* select month control */
$select_month_control = ‘’;
for($x = 1; $x <= 12; $x++) {
$select_month_control.= ‘<option value="’.$x.’"’.($x != $month ? ‘’ : ’ selected=“selected”’).’>’.date(‘F’,mktime(0,0,0,$x,1,$year)).’’;
}
$select_month_control.= ‘’."\n";
/* select year control */
$year_range = 4;
$select_year_control = ‘’;
for($x = ($year-floor($year_range/2)); $x <= ($year+floor($year_range/2)); $x++) {
$select_year_control.= ‘<option value="’.$x.’"’.($x != $year ? ‘’ : ’ selected=“selected”’).’>’.$x.’’;
}
$select_year_control.= ‘’."\n";
/* “next month” control */
$next_month_link = ‘Next Month >>’;
/* bringing the controls together */
$controls = ‘’.$previous_month_link.’ ‘.$select_month_control.$select_year_control.’ ‘.$next_month_link.’ ';
//CODING REMOVED
echo draw_calendar($month,$year,$events);[/code]
Here is the SQL query if that helps:SELECT Events.EventTitle, DATE_FORMAT(Performance.startDateTime, '%Y-%m-%e') AS event_date,
DATE_FORMAT(Performance.startDateTime, '%h:%i %p') AS start_time, Events.EventID, Events.ShoWareEventLink, Events.group_id, Performance.category_id
FROM Events LEFT JOIN Performance ON Events.EventID = Performance.EventID WHERE Events.group_id=1 AND Performance.category_id!=5 AND Performance.category_id!=7
AND Performance.category_id!=8 AND DATE_FORMAT(Performance.startDateTime,'%Y')=$year AND DATE_FORMAT(Performance.startDateTime,'%m')=$month
What currently happens with my calendar is that it will list events for THIS month and the next three months. After that it hits next year (January 2012) and the calendar goes blank. It will also go blank if you choose Previous month (even though there are events that happened in September 2011 and before. You can see this if you go to http://www.myalaskacenter.com/calendars/calendarSample3.php.
It appears that the ARRAY is working, it’s just not plugging into the calendar grid. Here’s the code where it is supposed to display items in the calendar grid:[code] /* keep going with days… / To see the fact that the ARRAY is working, check out http://www.myalaskacenter.com/calendars/calendarBroken.php?month=1&year=2012. As you can see by the URL it is putting the variables into the URL correctly, but the code that is supposed to complete the calendar grid is apparently not reading the variables. Does anyone know what should be done to the code to fix this?
for($list_day = 1; $list_day <= $days_in_month; $list_day++){
$calendar.= ‘
/ add in the day number */
$calendar.= ‘
’;
$event_day = $year.'-'.$month.'-'.$list_day;
if(isset($events[$event_day])) {
foreach($events[$event_day] as $event) {
if($event['category_id'] !=2){
$calendar.= '<div class="events">♦ <a href="' . $event['ShoWareEventLink'] . '">'.$event['start_time'].' - '.$event['EventTitle'].'</a></div>';
//^this is where we put the performance info
}
}
} else {
$calendar.= str_repeat('<p> </p>',2);
//^this is where we have blanks if an event_day <> list_day
}[/code]