Help with PHP calendar
Posted: Wed Aug 20, 2003 1:47 pm
Hello, I'm writing an app that allows the user to select a day from a calendar. It should only display one week out from the current day. It works great, however, when it reaches within 7-8 days of the end of the month, it blows up(doesn't print any days at all). Any help would be great.
Code: Select all
<?php
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix
// If the $Month and $Year values don't exist, make them the current month and year.
$Month = date ("m");
$Year = date ("Y");
$Day = date("d");
// Calculate the viewed Month.
$Timestamp = mktime (0, 0, 0, $Month, $Day, $Year);
$MonthName = date("F", $Timestamp);
// Make a table with the proper month.
?>
<form action="Sched2.php" method="post">
<CENTER><TABLE>
<TR>
<TD>
<?
print ("<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 ALIGN=CENTER>");
print ("<TR BGCOLOR=BLUE><TD COLSPAN=7 ALIGN=CENTER><FONT COLOR=WHITE><B>$MonthName $Year</B></FONT></TD></TR>");
print ("<TR BGCOLOR=BLUE><TD ALIGN=CENTER WIDTH=20><B><FONT COLOR=WHITE>Su</FONT></B></TD><TD ALIGN=CENTER WIDTH=20><B><FONT COLOR=WHITE>M</FONT></B></TD><TD ALIGN=CENTER WIDTH=20><B><FONT COLOR=WHITE>Tu</FONT></B></TD><TD ALIGN=CENTER WIDTH=20><B><FONT COLOR=WHITE>W</FONT></B></TD><TD ALIGN=CENTER WIDTH=20><B><FONT COLOR=WHITE>Th</FONT></B></TD><TD ALIGN=CENTER WIDTH=20><B><FONT COLOR=WHITE>F</FONT></B></TD><TD ALIGN=CENTER WIDTH=20><B><FONT COLOR=WHITE>Sa</FONT></B></TD></TR>\n");
$MonthStart = date("w", $Timestamp);
if ($MonthStart == 0) {
$MonthStart = 7;
}
$LastDay = date("d", mktime (0, 0, 0, $Month, $Day+8, $Year));
$StartDate = -$MonthStart;
$bgRGB = "white";
for ($k = 1; $k <= 2; $k++)
{ // Print 2 rows.
print ("<TR BGCOLOR=WHITE>");
for ($i = 1; $i <= 7; $i++)
{ // Use 7 columns
$StartDate++;
if (($StartDate <= 0) || ($StartDate > $LastDay))
{
print ("<TD BGCOLOR=GREEN> </TD>");
}
elseif ( ($StartDate >= 1) &&($Day < $LastDay ))
{
print ("<TD ALIGN=CENTER BGCOLOR="$bgRGB"><input type="Submit" name="SchedDay" value="$Day"></TD>");
$Day++;
if ($Day >= date("t",$Timestamp))
{
$Day = 1;
$bgRGB = "yellow";
}
}
}
print ("</TR>\n");
}
print ("</TABLE>\n");
?>
</TD>
</table></CENTER></form>
Yellow background on calendar is the start of a new month.
?>