the second loop work correctly for the first looping from the first loop, after that just execute the first loop without the second loop.can someone tell me where mistake from this code :
<form method="POST" action="#">
<?php
$no=0;
while($soal=mysql_fetch_array($result)){
$now=++$no;
echo $now.". ".$soal['soal']."<p>";
while($jawaban=mysql_fetch_array($result2)){ ;
?>
<p>
<input type=radio name="grup[<?php $now?>]" value="<?php $jawaban['idJawaban']?>"><?php echo $jawaban['jawaban']?><br>
<?php
}
}
?>
<input type="submit" value="submit">
</form>
Think about why the loop ever stops in the first place! while (..)
needs to stop at some point. That point is when mysql_fetch_array($result2)
finally returns false
. Why does it return false
? Because you're at the end of the result set. Trying to fetch a record from this result set will return false
, because the set is exhausted. Restarting the while
loop does not change that.
You either need to mysql_data_seek
back to the beginning of the result set, or you need to loop over the result set once and store all its data in an array, which you can loop over again and again.