hello,
I have multiple-choice questions in a table.
The first question is shown and the user submits the answer.Then i display if the answer is correct or wrong and then i would like to proceed for the next question.
I've done upto checking the answers and now i dont know how to get the next question.
Could somebody pls help me with the snippet.
You can see the working example HERE
Heres the code i got it so far.
<?php
include("contentdb.php");
if ($id == "")
{
$id = "0";
}
$display = mysql_query("SELECT * FROM $table WHERE id > $id ORDER BY id ASC LIMIT 1 ",$db);
if (!$submit) {
echo "<form method=post action=$PHP_SELF>";
echo "<table border=0>";
while ($row = mysql_fetch_array($display)) {
$id = $row["id"];
$question = $row["question"];
$opt1 = $row["opt1"];
$opt2 = $row["opt2"];
$opt3 = $row["opt3"];
$answer = $row["answer"];
echo "<tr><td colspan=3><br><b>$question</b></td></tr>";
echo "<tr><td>$opt1 <input type=radio name=q$id value=\"$opt1\"></td><td>$opt2 <input type=radio name=q$id value=\"$opt2\"></td><td>$opt3 <input type=radio name=q$id value=\"$opt3\"></td></tr>";
}
echo "</table>";
echo "<input type='submit' value='See how you did' name='submit'>";
echo "</form>";
}
elseif ($submit)
{
echo "</p>";
echo "<p>Here are the answers:";
echo "<table border=0>";
$display = mysql_query("SELECT * FROM $table WHERE id > $id ORDER BY id ASC LIMIT 1",$db);
while ($row = mysql_fetch_array($display)) {
$question = $row["question"];
$answer = $row["answer"];
$q = $row["q"];
echo "<tr><td><br>$question</td></tr>";
if ($$q == $answer)
{
echo "<tr><td>»you answered ${$q}, which is correct</td></tr>";
}
elseif ($$q == "") {
echo "<tr><td>»you didn't select an answer. The answer is $answer</td></tr>";
}
else {
echo "<tr><td>»you answered ${$q},which is wrong. The answer is $answer</td></tr>";
}
}
echo "</table></p>";
}
?>