"for" loop inside another "for" loop
- by jnkrois
Hello everybody.
I have quick question, and I'm sure some of you guys will be able to point out what I'm doing wrong.
Basically, I want to create a table with (calendar), with the months and days of an entire year, and Im using php to do it, my code is doing something weird.
What happens is that January is empty and the days for January are being put in february.
My code so far is as follows:
$months = 12;
$monthsOfTheyear = array("Januany","February","March","April","May","June","July","August","September","October","November","December");
$currentMonth = date("n");
$currentYear = date("Y");
$daysOfTheMonth = cal_days_in_month(CAL_GREGORIAN, $currentMonth, $currentYear);
for($i = 0; $i < $months; $i++){
echo " <tbody class='month'>";
echo " <tr>
<td colspan='".$daysOfTheMonth."'>
".$monthsOfTheyear[$i]."
</td>
</tr>
<tr>
";
$daysOfEachMonth = cal_days_in_month(CAL_GREGORIAN, $i, $currentYear);
for($d = 1; $d <= $daysOfEachMonth; $d++){
echo " <td>
".$d."
</td>
";
}
echo " </tr>
</tbody";
}
I'm obviously doing something wrong, but I've been staring at the monitor for about an hour trying to figure it out.
I'd appreciate any advice.
Thanks