Resetting a while loop
- by Patrick Beardmore
I have found a confusing thing in a php script I am writing to generate some javascript. Here it is below, slightly simplified.
The second while loop won't run unless I comment out the entire first while loop. Can anyone explain why? Many thanks.
<?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++;
}
?>