나는 자바 스크립트를 생성하기 위해 작성한 PHP 스크립트에서 혼란스러운 것을 발견했습니다. 여기 아래에 약간 단순화되어 있습니다.while 루프 재설정
첫 번째 while 루프 전체를 주석 처리하지 않으면 두 번째 while 루프가 실행되지 않습니다. 왜 그 이유를 설명 할 수 있습니까? 많은 감사합니다.
<?php
$listid = 2; //DEMO ONLY
$result1 = mysql_query("SELECT words.wid,words.wordmd5,words.word FROM words,instances WHERE words.wid = instances.wid AND instances.lid = \"$listid\"");
$result1copy = $result1;
$count1 = 1;
while($row = mysql_fetch_object($result1))
{
print "words_left[$count1] = \"".$row->word."\";\n";
//Increment the array counter (starts at 1)
$count1++;
}
?>
//Some javascript
<?php
$count2 = 1;
while($row = mysql_fetch_object($result1copy))
{
print "
$count2 then $row->wordmd5
";
$count2++;
}
?>
무한 루프입니다. 당신은'$ count1'을 증가 시키지만, while 루프는'true'를 항상 리턴하는'$ row'를 테스트하고 있습니다. – Kai
@Kai : $ row는 항상 true가 아니며, 모든 레코드가 처리 될 때 null이됩니다. – Chetan