Is there a way i can retrieve all questions from the database related to that quiz on one page?
Code: Select all
<?php
session_start();
// This script handle all the user commands.
require_once ("database.php");
require_once ("globals.php");
require_once ("loginlib.php");
$usertype = Getusertype ();
$username = Getusername ();
$userid = Getuserid ();
$title = $g_system_name . " -- Dashboard";
ShowHeader ($title);
ShowLinks (5);
?>
<?
//require_once ('mysql_connect.php'); // Connect to the db.
mysql_connect("localhost", "root", "") or die ("Unable to connect to the server");
// select the database or return an error message
mysql_select_db("nluser") or die ("Unable to connect to the database");
//get the id if the quiz that is to taken
$id = $_GET['id'];
echo "Quiz ID: ".$id; ?>
<br><br>
<?
//$query = "SELECT * FROM questions WHERE quizID='$id' ";
//$result=mysql_query($query);
//echo mysql_query($query);
$result = mysql_query("SELECT * FROM questions WHERE quizID='$id'");
//while($row = mysql_fetch_row($result))
//{
//echo $row['question_no'].",".$row['question']."<br/>";
//sergeys
//echo "query works<br>";
$answers = array();
$question="";
$answerblock=array();
$rightanswer=array();
//echo "arrays work<br>";
//{
//print_r($row);
if(mysql_numrows($result))
{
while($rows = mysql_fetch_row($result))
{
print('<form name=myform method="post" action="quizresults.php">');
//$rows = mysql_fetch_row($result);
//print_r($row);
//echo "start of the while loop - under the form<br>";
$qid=$rows[0];
$question=$rows[1];
$answers[0]=$rows[3];
$answers[1]=$rows[4];
$answers[2]=$rows[5];
$answers[3]=$rows[6];
$question_no=$rows[2];
$rightanswer=$rows[3];
//echo "assign values to array<br>";
srand((float) microtime() * 10000000);
$rand_keys = array_rand($answers, 4);
$answer0=$answers[$rand_keys[0]] ;
$answer1=$answers[$rand_keys[1]] ;
$answer2=$answers[$rand_keys[2]] ;
$answer3=$answers[$rand_keys[3]] ;
print('<tr><td><input type="radio" name=answer value="'.$answer0 .'"> '.$answer0.'</td></tr>');
print('<tr><td><input type="radio" name=answer value="'.$answer1 .'">   '.$answer1 .'</td></tr>');
print('<tr><td><input type="radio" name=answer value="'.$answer2 .'">   '.$answer2 .'</td></tr>');
print('<tr><td><input type="radio" name=answer value="'.$answer3 .'">   '.$answer3 .'</td></tr><br>');
print('<tr><td> <input type=hidden name=rightanswer value="'.$rightanswer .'"></tr>');
print('<tr><td colspan=2><input type=submit name=submit value="Submit" >
              
            
<input type=reset name=reset value="reset" ></td></tr></table>');
print('</form>');
}
//print('<tr><td> <input type=hidden name=rightanswer value="'.$rightanswer .'"><input type= hidden name=qnumber value="'.$qnumber .'"></tr>');
}
?>
</form>
<?
ShowFooter();
?>