-1

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>
  • I have no idea what you are talking about, include your queries and we might have a chance to figure it out. – Epodax Aug 10 '15 at 07:41
  • example of code result : 1. question1 ( a. b. c. d.) 2. question2 () 3. question3() – Ryan Irfandi Aug 10 '15 at 07:55
  • **Warning**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Aug 10 '15 at 08:01

1 Answers1

1

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.

deceze
  • 510,633
  • 85
  • 743
  • 889