Dear Coders,
I am having a slight problem with the following calendar code. What I would like it to do is start the 1st on the corresponding day of the week. So far I have not been able to get my code to correspond. If anyone here is able to assist with this small issue I would greatly appreciate it. Here is the glorious code.
<?php
/**
Calendar Program
This program was designed for the use of PRA International Only
@version 1.0
@copyright Alex Autrey August, 31 2005
*/
$day_num = date('j');
$year = date('Y');
$wday = date('w');
$day_n_month = date('t');
$month = date('n');
$text_wday = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
$text_month = array("", "January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
?>
<table border="1">
<tr>
<td colspan="7" align="center"><a href="?prev"><.</a> <? echo "$text_month[$month]"; ?><a href="?next">.></a></td>
</tr>
<?
echo '<tr>';
for($i=0; $i <= 6; $i++){
echo '<td align=center>';
echo "$text_wday[$i]";
echo '</td>';
}
echo '</tr>';
//Find out what day the first day of the month fell on.
//This gives us a starting location.
if($day_num==1){
$first_day = $wday;
} else {
for($i=$day_num; $i==1; $i--){
$wday--;
if($wday == -1){
$wday = 6;
}
}
$first_day = $wday;
}
echo '<tr>';
for($i = 0; $i <= $day_n_month; $i++){
if($wday == $first_day){
if($wday == 7){
echo '</tr><tr>';
echo '<td>';
echo $i;
echo '</td>';
$wday = 0;
} else {
echo '<td>';
echo $i;
echo '</td>';
}
} else {
echo '<td> </td>';
}
$wday++;
}
echo '</tr>';
?>
</table>