"for" loop doesn't break every time, can't find th
Posted: Sun Sep 09, 2007 3:38 am
Hi, here's my for loop:
Before that loop there are 5 values set - $day, $month, $year, $timestamp (timestamp of the first day of the month) and $tableWeek=0 (it indicates current table cell's position, to know what day to put on that cell or to skip that cell.
The problem is, that the browser crashes when specific month is chosen. For example, it displays 2007 year 9 and 11th months perfectly, but on 10th month the browser crashes and I can't fins the problem which causes that. I think the "for" loop somehow becomes infinitive on that month, but I can't find where. When another month is reached, it should break the loop.
Thanks for any help.
Code: Select all
<table border=1 cellpadding=5 cellspacing=5 width=100%>
<tr>
<td width=14% align=center><b>Sunday</b></td>
<td width=14% align=center><b>Monday</b></td>
<td width=14$ align=center><b>Tuesday</b></td>
<td width=14% align=center><b>Wednesday</b></td>
<td width=14% align=center><b>Thursday</b></td>
<td width=15% align=center><b>Friday</b></td>
<td width=15% align=center><b>Saturday</b></td>
</tr>
<tr align=center>
<?php
for (;;) {
if ($date['wday'] != $tableWeek) {
for (; $date['wday'] != $tableWeek; ++$tableWeek) {
echo "<td></td>\n";
}
echo "<td bgcolor=\"#7FFFD4\" id=\"{$date['mday']}\" onclick=\"changeCol({$date['mday']})\" align=center style=\"font-size:24px; font-weight:bold;";
if ($date['wday'] == 0 || $date['wday'] == 6) {
echo " color:red;";
}
echo "\">";
echo date("j", $timestamp);
echo "</td>\n";
$tableWeek++;
if ($tableWeek > 6) {
echo "</tr>\n<tr>";
$tableWeek = 0;
}
}
else {
echo "<td bgcolor=\"#FFFFFF\" id=\"{$date['mday']}\" onclick=\"changeCol({$date['mday']})\" align=center style=\"font-size:24px; font-weight:bold;";
if ($date['wday'] == 0 || $date['wday'] == 6) {
echo " color:red;";
}
echo "\">";
echo date("j", $timestamp);
echo "</td>\n";
$tableWeek++;
if ($tableWeek > 6) {
echo "</tr>\n<tr>";
$tableWeek = 0;
}
}
$timestamp += 60 * 60 * 24;
$date = getdate($timestamp);
if ($date['mon'] > $month || $date['mon'] < $month) {
break; // break loop if another month was reached
}
}
echo "</tr></table>\n<br><br>";The problem is, that the browser crashes when specific month is chosen. For example, it displays 2007 year 9 and 11th months perfectly, but on 10th month the browser crashes and I can't fins the problem which causes that. I think the "for" loop somehow becomes infinitive on that month, but I can't find where. When another month is reached, it should break the loop.
Thanks for any help.