PHP event calendar

My code is not working properly…i.e, aug’5 is display the out of column…

php

<?php if (isset($_GET['day'])){ $day = $_GET['day']; } else{ $day = date("j"); } if (isset($_GET['month'])){ $month = $_GET['month']; } else{ $month=date("n"); } if (isset($_GET['year'])){ $year = $_GET['year']; } else{ $year=date("Y"); } $currentTimeStamp=strtotime("$year-$month-$day"); $monthName=date("F", $currentTimeStamp); $numDays=date("t", $currentTimeStamp); $counter = 0; ?>
<tr>
   <td><input style="width:50px;" type="button" value="<<" name="Previous"></td>
   <td colspan="5"> <?php echo $monthName.",".$year; ?></td>
   <td><input style="width:50px;" type="button" value=">>" name="Next"></td>
</tr>

<tr>
   <td width="50px;">Sun</td>
   <td width="50px;">Mon</td>
   <td width="50px;">Tue</td>
   <td width="50px;">Wed</td>
   <td width="50px;">Thu</td>
   <td width="50px;">Fri</td>
   <td width="50px;">Sat</td>
</tr>
<?php
echo "<tr>";

for ($i=1; $i<$numDays+1; $i++, $counter++){
	$timeStamp = strtotime("$year-$month-$i");
	if ($i==1){
		
		$firstDay = date ("w", $timeStamp);
		
		for($j=0;$j<$firstDay; $j++, $counter++){
			echo "<td>&nbsp;</td>";
		}
	}
	
	echo "<td>".$i."</td>";
	if($counter % 7 == 0){
		echo "</tr><tr>";
	}
}

echo "</tr>";

?>

php

try
[php]$counter = 1;[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service