Here's a chunk of code from my calendar script. This generates a small calendar for a single month previous to current month. So right now will generate Dec 2000. My calendar has one large display with the current month with events, and a small previous and next month calendar. (I hope I got all the code needed, but it should at least give you ideas, and addresses the how to get which day of the week to start on).
/ Figure out what month it is, convert the number to words, and then create
a table with days of the week headers, generate mini calendars for prev and next months /
echo "<table border='0' cellpaddig='0' cellspacing='0' width='100%'><tr>";
/ previous month mini cal /
echo "<td width=20%><table border=1><tr><th colspan=7>";
$ptDate = mktime(0,0,0,$pmonth,1,$pyear);
$lm = $month - 1;
$ly = $year - 1;
if ($month == '01') {
echo "<a href='index.phtml?month=12&year=$ly'>";
echo date('F', $ptDate) .", $pyear</a></th></tr><tr>\n";
echo "</a></font>";
} elseif ($month > 1 AND $month < 11) {
echo "<a href='index.phtml?month=0$lm&year=$year'>";
echo date('F', $ptDate) .", $pyear</a></th></tr><tr>\n";
echo "</a></font>";
} else {
echo "<a href='index.phtml?month=$lm&year=$year'>";
echo date('F', $ptDate) .", $pyear</a></th></tr><tr>\n";
}
echo "<td class=Q><b><font face='Arial'>S</font></b></td>";
echo "<td class=Q><b><font face='Arial'>M</font></b></td>";
echo "<td class=Q><b><font face='Arial'>T</font></b></td>";
echo "<td class=Q><b><font face='Arial'>W</font></b></td>";
echo "<td class=Q><b><font face='Arial'>T</font></b></td>";
echo "<td class=Q><b><font face='Arial'>F</font></b></td>";
echo "<td class=Q><b><font face='Arial'>S</font></b></td></tr>";
echo "<tr>";
while ($pday<$pdate):
/ Figure what day of the week the first falls on and set the number of
preceding and trailing cells accordingly /
if ($pday == '01') {
$poff = date('w',mktime(0,0,0,$pmonth,$pday,$pyear));
for ($pi=0; $pi<$poff; $pi++)
echo "<td></td>\n";
$poff++;
}
if ($ver >= 4) {
echo "<td CLASS=QX valign='top'>$pday<br>\n";
echo "</td>";
} else {
echo "<td valign='top'>$pday<br>\n";
echo "</td>";
}
/ Increment the day and the cells to go before the end of the row and end the
row when appropriate /
$pday++;
$poff++;
if ($poff>7) {
echo "</tr><tr>";
$poff='01';
} else {
echo "";
}
endwhile;
echo "</tr></table>