I am trying to make a quiz using PHP and Mysql. I have create my database and filled it. The database is construct as follows: question_id(P.K),question, right answer, annswer1,answer2, answer3,level and test_id(F.K).
I have created a query that “draws” questions in a random order and I have shuffled the answers. The PHP script for showing the Qs and As to the user is the following:
while ($index <= (count($test)-1)){
echo $test[$index]['question']. "<br/>";
$question_id=$test[$index]['question_id'];
$s_ans=User_Model::shuffle_answers($question_id);
foreach ($s_ans as $s_a){
echo "<input type='radio' name='test_ans[$index][$s_a]' id='$question_id' />$s_a <br />";
}
echo "<hr/>";
$index++;
}
The above code shows all questions and their answers at once.
What I would like to do, and couldn’t successfully get it done, is to show each question separately and when the user presses the “next” button, the next question accompanied by its answers will be shown to him.
So,
a)is there a way I can achieve that?
b)when I try to access user’s answers I get the following output:
Array ( [0] => Array ( [I like ice cream => on ) [1] => Array ( [i don't go to school] => on ) [2] => Array ( [i play basketball] => on ) [3] => Array ( [i like sailing] => on ) )
How can i access the user’s answers as to compare them with the right answer?
Multipage quizzes are very easy to do.
A) This can be done by removing the
while()loop, but leave the counter to pass through a hidden<input>OR increasing the$_SESSIONvariableB) Without your code, this is just an example –