Skygal Posted September 13, 2008 Share Posted September 13, 2008 Hi - I have a calendar that is changing the days, and finding the first day ok when next or prev is clicked on, but it doesn't change the heading to reflect the new month. Does anyone have a hint for me? I'm stuck and can't think where to go next. thanks. My code is below: <?php $year = date("Y"); // current year - 2008 $mo = date("F"); // September for September if (isset($_GET['month'])) $month = $_GET['month']; else $month = date("n"); // 9 for September print ("<html>\n"); print ("<head>\n"); print ("<title></title>\n"); print ("</head>\n"); print ("<body>\n"); // Output to HTML table (frame in grey) print ("<table style='border:1px solid grey' width='350' cellspacing='0' align='center'>\n"); print ("<tr>\r\n"); // PREV and NEXT rows // First get the previous month $prevMonth = $month - 1; print ("<td><a href='a2.php?month=$prevMonth&year=$year'>PREV</a></td>\n"); // blank spaces for between PREV and NEXT print ("<td colspan='5'> </td>\n"); // Then get the next month $nextMonth = $month + 1; print ("<td><a href='a2.php?month=$nextMonth&year=$year'>NEXT</a></td>\n"); print ("</tr>\n"); print ("<tr>\n"); // Month and year row print ("<th colspan='7'><h2>$mo $year</h2></th>\n"); //echo "<a href='", $_SERVER['SCRIPT_NAME'], $month+1, "'>", "Next</a>\n"; print ("</tr>\r\n"); print ("<tr>\r\n"); // horizontal line print ("<td colspan='7' ><hr /></td>"); print ("</tr>\r\n"); print ("<tr style='background:lightgrey;'>\r\n"); // day initials print ("<td width='50' align='center'>S</td>\n"); print ("<td width='50' align='center'>M</td>\n"); print ("<td width='50' align='center'>T</td>\n"); print ("<td width='50' align='center'>W</td>\n"); print ("<td width='50' align='center'>T</td>\n"); print ("<td width='50' align='center'>F</td>\n"); print ("<td width='50' align='center'>S</td>\n"); print ("</tr>\r\n"); print "<tr>\n"; $date = mktime(12, 0, 0, $month, 1, $year); $daysInMonth = date("t", $date); // calculate position of the first day in the calendar (sunday = 1st) $firstDay = date("w", $date); $rows = 1; // blank tds before first day for($blanktd = 1; $blanktd <= $firstDay; $blanktd++) { print "<td></td>"; } for($day = 1; $day <= $daysInMonth; $day++) { if( ($day + $firstDay - 1) % 7 == 0 && $day != 1) { print "</tr>\n\t<tr>"; $rows++; } print "<td align='center'>" . $day . "</td>"; } print "</tr>\n"; print ("</table>\n"); print ("</body>\r\n"); print ("</html>\r\n"); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.