Hello,I'm doing a sample quiz for students.I have 25 questions displaying 1 question per page with a next button.I also manage to count its correct answers.And if all the questions have already shown from database,it prints that there are no more questions left.But I want to keep track of the questions which have no answers.So that if a student, wants to skip a question, he/she can go back to it.I hope you can help me.Here is my code.
<?php
session_start();
include('config.php');
if(!isset($a))
{
$a=0;
//unset($_SESSION['score']);
}
if(isset($_POST['next'])) {
$a=$_POST['a'];
if($_POST['a']==25) {
echo "There are no more questions in this part";
}
}
$sql1="SELECT * FROM questionpart2 ORDER by qid LIMIT 1 OFFSET $a";
$result=mysql_query($sql1);
$num = mysql_num_rows($result);
echo "<form method='post' action=''>";
if($result) {
while ($row = mysql_fetch_array($result))
{
$qid = $row["qid"];
$questions = $row["question"];
$opt1 = $row["choice1"];
$opt2 = $row["choice2"];
$opt3 = $row["choice3"];
$opt4 = $row["choice4"];
$answer = $row["answer"];
echo" ";
echo '<p>'.$x.'. ' . $questions . '</p>
<input type="radio" name="choice[' . $qid . ']" value="' . $opt1 .'"/>A.' . $opt1 . '
<input type="radio" name="choice[' . $qid . ']" value="' . $opt2 .'"/>B.' . $opt2 . '
<input type="radio" name="choice[' . $qid . ']" value="' . $opt3 .'"/>C.' . $opt3 . '
<input type="radio" name="choice[' . $qid . ']" value="' . $opt4 .'"/>D.' . $opt4 . '
<input type="hidden" name="question_id" value"'.$qid.'"/>
<input type="hidden" name="rightanswer[' . $qid . ']" value="' . $answer . '" />';
echo "<input type='submit' name='next' value='next'><br><br>";
}
$b=$a+1;
echo "<input type='hidden' value='$b' name='a'>";
echo "<input type='hidden' value='count' name='count'>";
echo "</form>";
}
?>
<?php
if(isset($_POST['choice']))
{
//$_SESSION['qid'] = $_POST['question_id'];
$_SESSION['score'] = (!$_SESSION['score']) ? 0 : $_SESSION['score'];
foreach($_POST['choice'] as $qid => $answer)
if($_POST['rightanswer'][$qid] == $answer) {
$_SESSION['score']++;
}
echo " Score is " . $_SESSION['score'];
}
?>