How can I do this with PHP?

myscranton

New member
I am working on a simple calendar for my website wriiten in PHP. It works fine except I can't figure out how to switch between months. This is what I currently have to move to the previous month, but the problem is it only works once. It'll go back one month but wont work any more. Can anyone help me fix this?

<?php
$day = date("d");
$month = date("m");
$year = date("Y");
$month2 = date("F");

while (isset($_POST['image_x'])) {
$month = date("m", strtotime("-1 month"));
$month2--;
}

$month_length = date('t', mktime(0, 0, 0, $month, $day, $year));
$first_day = date('w', mktime(0, 0, 0, $month, 1, $year));
$next_row = $first_day;
for($i=1; $i<=$first_day; $i++)
{
$start.="<td>Â*</td>";
}
echo "<table width='225' class='calendar'><tr><td style='background-color:#FFFFDD'><form name='calendar' action='" . $_SERVER['PHP_SELF'] . "' method='post'><input type='image' src='/images/prev_month.png' onmouseover=\"this.src='/images/prev_month_hover.png'\" onmouseout=\"this.src = '/images/prev_month.png'\" name='image'></form><td style='background-color:#FFFFDD; font-family:Tahoma; font-size:20px; text-align:center' colspan=5><b>".$month2.", ".$year."</b></td></tr><tr><td class='day'>Sun</td><td class='day'>Mon</td><td class='day'>Tue</td><td class='day'>Wed</td><td class='day'>Thu</td><td class='day'>Fri</td><td class='day'>Sat</td></tr><tr>";

for ($x=1;$x<=$month_length;$x++) {
echo $start."<td class='date'>$x</td>";
$start = '';
$next_row++;
if ($next_row == 7) {
echo "</tr><tr>";
$next_row = 0;
}
}
echo "</table>";
?>
 
Back
Top