Here is my problem
all months start from day 1
but month 7 2012
start from day 2
don’t know why
and here is the code
<table>
<?php
$cMonth = 7;
$cYear = 2012;
$first_day_timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$first_day_timestamp);
$thismonth = getdate($first_day_timestamp);
$startday = $thismonth['wday'] - 1;
for ($i=0; $i<($maxday+$startday); $i++) {
if (($i % 7) == 0 ) echo "<tr>";
if ($i < $startday) { echo "<td> </td>" ; continue; }
$current_day = $i - $startday + 1;
echo "<td>". $current_day . "</td>";
if (($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
Image attached

Please tell me why this happened
Why are you doing this:
??
You’re moving the day offset back one. This is effectively saying the day you want to start counting on is one day before the first day of the month.
–EDIT–
So you’re doing that because you want the calendar to start on Monday instead of Sunday. php’s wday is this:
You’re subtracting one from it will shift the start of the month down one day until and unless the month starts on Sunday. Then $startday is -1 and it throws off your counting. You need it to wrap around to the previous week instead. If you add another line that fixes this case like:
It should fix the problem. I’m sure there’s other ways to compensate for Monday being the first day of the week though.