为什么"如果"声明导致"而"循环冻结浏览器?

时间:2015-04-15 13:15:53

标签: php if-statement browser while-loop crash

我有点有趣的问题。将 if 语句添加到我的 while循环 with-in PHP函数后,运行该站点的我的(Chrome)浏览器窗口将不会响应。我已经通过评论来验证这是 if 语句导致问题。如果 if 语句被注释掉,那么一切都很好。

两个循环的结果相同。

function disp_editForm($id, $day, $month, $year, $type, $content) {
$d_count = 0;
$m_count = 0;

echo '<select name="editDay" id="editDay" onchange="" size="1">';
while($d_count<31) {
$d_count++;
if($d_count=$day) { $dSelected = "selected"; } // Select value in the drop box
echo '<option value="'.$d_count.'"'.$dSelected.'>'.$d_count.'</option>';
} // End Day While Loop
echo '</select>';

echo '<select name="editMonth" id="editMonth" onchange="" size="1">';
while($m_count<12) {
$m_count++;
if($m_count=$month) { $mSelected = "selected"; } // Select value in the drop box
echo '<option value="'.$m_count.'"'.$mSelected.'>';
mConvert($m_count); // Convert month number into a word
echo '</option>';
} // End Month While Loop
echo '</select>';

}

2 个答案:

答案 0 :(得分:4)

if($d_count=$day) { $dSelected = "selected"; }
if($m_count=$month) { $mSelected = "selected"; }

应该是

if($d_count==$day) { $dSelected = "selected"; }
if($m_count==$month) { $mSelected = "selected"; }

您在此处执行作业(=)而非平等比较(==)。

答案 1 :(得分:2)

使用等式比较运算符==代替=

f($d_count==$day) { $dSelected = "selected"; }
if($m_count==$month) { $mSelected = "selected"; }
相关问题