我正在使用PHP来帮助为网页创建一个表,但似乎无法发现这个while循环导致浏览器崩溃的位置。
<?php
$counter1 = 1;
$weekDay = date('l');
echo "Today is $weekDay " . date("Y/m/d") . "<br/>";
echo "<h1>Table Construction</h1>";
echo "<table><tr>";
$dateNow = date("Y/m/d");
$dayStore = array();
while ($counter1 < 8) {
$stringCheck = "+" . $counter1 . " day";
$dateMod = strtotime($stringCheck, strtotime($dateNow));
$weekDay = date ('D',$dateMod);
echo "<td id=\"bolder\">" . date ('l',$dateMod) . " " . date("Y/m/d", $dateMod). "</td>";
$dayStore[$counter1]=$weekDay;
$counter1++;
}
echo "</tr>";//"<tr>";
$counter1=1;
while ($counter1<8){
echo "<td><form name=\"timeslots\">";
$dayVar = $dayStore[$counter1];
echo $dayVar. " ";
$counterHours = 0;
if ($dayVar == "Mon"||$dayVar == "Tue"||$dayVar == "Wed"||$dayVar == "Thu"||$dayVar == "Fri") {
$startTime = 9;
$counterHours = 0;
while ($counterHours<3) {
$timeString = $startTime . ":00 am";
echo "<input type=\"radio\" name=\"$dayStore[$counter1]\" value=\"$startTime\">$timeString</input><br/>";
$startTime = $startTime+1;
$counterHours++;
}
while (startTime<12 && $counterHours>=3) {
$timeString = ($startTime-12) . ":00 pm";
echo "<input type=\"radio\" name=\"$dayStore[$counter1]\" value=\"$startTime\">$timeString</input>";
$startTime = $startTime+1;
$counterHours++;
}
}
else if ($dayVar == "Sat") {
$startTime = 9;
$counterHours = 0;
while ($counterHours<3) {
$timeString = $startTime . ":00 am";
echo "<input type=\"radio\" name=\"$dayStore[$counter1]\" value=\"$startTime\">$timeString</input>";
$startTime = $startTime+1;
$counterHours++;
}
while ($counterHours<12 && $counterHours>=3) {
$timeString = ($startTime-12) . ":00 pm";
echo "<input type=\"radio\" name=\"$dayStore[$counter1]\" value=\"$startTime\">$timeString</input>";
$startTime = $startTime+1;
$counterHours++;
}
}
else if ($dayVar == "Sun") {
$startTime = 11;
$counterHours = 0;
while ($counterHours<3) {
$timeString = $startTime . ":00 am";
echo "<input type=\"radio\" name=\"$dayStore[$counter1]\" value=\"$startTime\">$timeString</input>";
$startTime = $startTime+1;
$counterHours++;
}
while ($counterHours<12 && $counterHours>=3) {
$timeString = ($startTime-12) . ":00 pm";
echo "<input type=\"radio\" name=\"$dayStore[$counter1]\" value=\"$startTime\">$timeString</input>";
$startTime = $startTime+1;
$counterHours++;
}
}
else {
echo "displaying a proper message";
}
echo "</form></td>";
$counter1++;
}
echo "</tr></table>";
?>
当我在我的主页面上传到我学校的服务器并运行它时,没有任何加载,浏览器崩溃。根据我选择的变量范围,我认为不应该这样做......
答案 0 :(得分:1)
错别字:
while (startTime<12 && $counterHours>=3) {
^^^^^^^^^ missing $
未定义的常量,因此被评估为0
,使表达式
while (0 < 12 && $counterHours>=3) {
while (true && true) {
while (true) {
因此是一个无限循环。
如果您在启用调试选项的情况下运行(例如display_errors
和error_reporting
),则会告诉您未定义的常量。这些设置应该在开发/调试系统上 NEVER 关闭。