I am creating a random generated quiz with 10 questions. In generating the random question is fine but i want to display also the choices in random same with the questions.
This is my code that I am currently working with.
> <?php generate(); function generate() { > include('connection.php'); mysql_select_db('exam'); > $result=mysql_query("SELECT * FROM questionaires INNER JOIN choices > ON questionaires.q_id=choices.q_id WHERE RAND()<(SELECT > ((10/COUNT(*))*10) FROM questionaires) ORDER BY RAND() LIMIT 10"); > $c=0; echo "<table border='3' align='center' > bordercolor='#CCCCCC'> <tr> <th>Number:</th> > <th>Question</th> </tr>"; > > while($row = mysql_fetch_array($result)) { > $c++; > echo "<tr>"; > echo "<td>" . $c . "</td>"; > echo "<td>"; > echo $row['question'] . "<br>"; > echo "<input type='radio' name='ans'>".$row['choice_a']."</input><br>"; > echo "<input type='radio' name='ans'>".$row['choice_b']."</input><br>"; > echo "<input type='radio' name='ans'>".$row['choice_c']."</input><br>"; > echo "<input type='radio' name='ans'>".$row['choice_d']."</input><br>"; > echo "</td>"; > echo "</tr>"; > //} > //} } echo "</table>"; } ?>
Little help will highly appreciated.
Aucun commentaire:
Enregistrer un commentaire