title: quiz: can not get the correct answer with rand()
body: <p>i got this code from technopoints, i want to get a random question from database but i cant work this out when i put the <code>$fetchqry = "SELECT * FROM quiz ORDER BY rand()";</code>  it does not get the correct result i think because of the rand().  i've been trying to fix this and it doesn't work and also how can i put an incremented number per question?</p>
  
  <pre><code>                                if (isset($_POST['click']) || isset($_GET['start'])) {
                                  @$_SESSION['clicks'] += 1 ;
                                  $c = $_SESSION['clicks'];
                                  if(isset($_POST['userans'])) { $userselected = $_POST['userans']; 
  
                                  $fetchqry2 = "UPDATE 'quiz' SET 'userans'='$userselected' WHERE 'id'=$c-1"; 
                                  $result2 = mysqli_query($db,$fetchqry2);
                                  }
  
  
                                  } else {
                                    $_SESSION['clicks'] = 0;
                                  }
  
                                  //echo($_SESSION['clicks']);
                                  ?&gt;
  
  
  &lt;div class="bump"&gt;&lt;br&gt;&lt;form&gt;&lt;?php if($_SESSION['clicks']==0){ ?&gt; &lt;button class="button" name="start" float="left"&gt;&lt;span&gt;START QUIZ&lt;/span&gt;&lt;/button&gt; &lt;?php } ?&gt;&lt;/form&gt;&lt;/div&gt;
  &lt;form action="" method="post"&gt;          
  &lt;table&gt;
    &lt;?php if(isset($c)) {   $fetchqry = "SELECT * FROM 'quiz' ORDER BY rand()";
          $result=mysqli_query($db,$fetchqry);
          $num=mysqli_num_rows($result);
          $row = mysqli_fetch_array($result,MYSQLI_ASSOC); }
        ?&gt;
  &lt;tr&gt;&lt;td&gt;&lt;h3&gt;&lt;br&gt;&lt;?php echo  @$row['que'];?&gt;&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt; &lt;?php if($_SESSION['clicks'] &amp;&amp; $_SESSION['clicks']){ ?&gt;
    &lt;tr&gt;&lt;td&gt;&lt;input required type="radio" name="userans" value="&lt;?php echo $row['option 1'];?&gt;"&gt;&amp;nbsp;&lt;?php echo $row['option 1']; ?&gt;&lt;br&gt;
    &lt;tr&gt;&lt;td&gt;&lt;input required type="radio" name="userans" value="&lt;?php echo $row['option 2'];?&gt;"&gt;&amp;nbsp;&lt;?php echo $row['option 2'];?&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;&lt;input required type="radio" name="userans" value="&lt;?php echo $row['option 3'];?&gt;"&gt;&amp;nbsp;&lt;?php echo $row['option 3']; ?&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;&lt;input required type="radio" name="userans" value="&lt;?php echo $row['option 4'];?&gt;"&gt;&amp;nbsp;&lt;?php echo $row['option 4']; ?&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;&lt;button class="button3" name="click" &gt;Next&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt; &lt;?php }  
                                    ?&gt; 
    &lt;form&gt;
   &lt;?php if($_SESSION['clicks']){ 
    $qry3 = "SELECT 'ans', 'userans' FROM 'quiz';";
    $result3 = mysqli_query($db,$qry3);
    $storeArray = Array();
    while ($row3 = mysqli_fetch_array($result3, MYSQLI_ASSOC)) {
       if($row3['ans']==$row3['userans']){
       @$_SESSION['score'] += 1 ;
     }
  }
  
   ?&gt;
  
  &lt;h2&gt;Result&lt;/h2&gt;
   &lt;span&gt;No. of Correct Answer:&amp;nbsp;&lt;?php echo $no = @$_SESSION['score']; 
   session_unset(); ?&gt;&lt;/span&gt;&lt;br&gt;
   &lt;span&gt;Your Score:&amp;nbsp&lt;?php echo $no*2; ?&gt;&lt;/span&gt;
  &lt;?php } ?&gt;```
  </code></pre>