Developing an event calendar in PHP. The page sets a variable called $mo_yr_in either to the current date on the first call of the page or to the value of selected_mo_yr which comes from using method='GET' and action='calendar.php' within <form> tags on the page which calls itself when the user selects a different month in a <select> control named selected_mo_yr and clicks the submit button. The value of selected_mo_yr will be a string representing the first day of the month and year selected (e.g. 2005-01-01).
The value of the $_GET['selected_mo_yr'] is stored to a variable called $mo_yr_in, from which $month_in and $year_in are extracted as criteria to query a mySQL database to populate the cells in the calendar. Another variable $first_of_month is extracted from $mo_yr_in to determine how many cells should be gray at the beginning of the month (like most calendars). The variable $days_in_month is used determine how many rows and cells are needed to show all the days in the month.
The first time the page is opened, it all works correctly and the variables all have the expected values. Selecting a different month and clicking GO works correctly to retrieve events for the desired month (indicating that the value of $_GET['selected_mo_yr'] is changing), however, the values for $first_of_month and $days_in_month don't change. The result is that no matter what month/year is selected, I always get 3 gray cells in the first row under Sun, Mon, and Tue, and first day of the month is in the first row under Wednesday, the same as the current month (December 2004).
Here's some of the code:
Why would the value of $mo_yr_in change but not the values of $first_of_month and $days_in_month when they are being determined from $mo_yr_in, which IS changing ?
I tried using unset($first_of_month,$days_in_month) after all the processing, but it made no difference.
All help is appreciated.
The value of the $_GET['selected_mo_yr'] is stored to a variable called $mo_yr_in, from which $month_in and $year_in are extracted as criteria to query a mySQL database to populate the cells in the calendar. Another variable $first_of_month is extracted from $mo_yr_in to determine how many cells should be gray at the beginning of the month (like most calendars). The variable $days_in_month is used determine how many rows and cells are needed to show all the days in the month.
The first time the page is opened, it all works correctly and the variables all have the expected values. Selecting a different month and clicking GO works correctly to retrieve events for the desired month (indicating that the value of $_GET['selected_mo_yr'] is changing), however, the values for $first_of_month and $days_in_month don't change. The result is that no matter what month/year is selected, I always get 3 gray cells in the first row under Sun, Mon, and Tue, and first day of the month is in the first row under Wednesday, the same as the current month (December 2004).
Here's some of the code:
Code:
[b][COLOR=red]<?php[/color][/b]
$mo_yr_in = $_GET['selected_mo_yr'];
if ($mo_yr_in == "") {
$mo_yr_in = date('Y-m-d');
}
$year_in = date('Y', strtotime($mo_yr_in));
$month_in = date('m', strtotime($mo_yr_in));
$first_of_month = date('w', $mo_yr_in);
$days_in_month = date('t', $mo_yr_in);
$sqlstring = 'SELECT event_day, event_year, event_month, event_time FROM events WHERE event_month = '. $month_in . ' And event_year = ' . $year_in . ' ORDER BY event_day, event_time';
[b][COLOR=red]?>[/color][/b]
[i]some other html stuff is here[/i]
[b][COLOR=red]<?php[/color][/b]
$columnpos = 0;
for($i = 0; $i < $first_of_month; $i++) {
echo "<td height=120 align=left valign=top bgcolor=#dcdcdc></td>";
$columnpos++;
}
$row = mysql_fetch_array($result);
for($j = 1; $j <= $days_in_month; $j++) {
echo '<td bgcolor=#ffffff height=120 align=left valign=top><span class=calendartxt>' . $j . '</span><br>';
}
[i]more php stuff follows[/i]
Why would the value of $mo_yr_in change but not the values of $first_of_month and $days_in_month when they are being determined from $mo_yr_in, which IS changing ?
I tried using unset($first_of_month,$days_in_month) after all the processing, but it made no difference.
All help is appreciated.