Hello everybody,
I'm looking for somebody who can help me with my script.I'm trying to mix up all the snippets of mine and its messed up.This is a simple question and anwer script, to be more precisely a quiz script.
First time, i show one question and when the user submit the answer, i would like to show the if the answer is right or wrong and then proceed to next question.THERE ARE ONLY 5 QUESTIONS.This is what i would like to do in my first phase.
Right now, i'm able to show the question and when the user submits it, i'm also showing the answer but the other questions are also visible.I need to put in the loop my query but somewhere its missing.Could somebody please help me to fix my script and also i need to show the next button or link for the user to proceed to the next question.There are only 5 questions.
you can see the working example HERE
Thanks a million.
I'm looking for somebody who can help me with my script.I'm trying to mix up all the snippets of mine and its messed up.This is a simple question and anwer script, to be more precisely a quiz script.
First time, i show one question and when the user submit the answer, i would like to show the if the answer is right or wrong and then proceed to next question.THERE ARE ONLY 5 QUESTIONS.This is what i would like to do in my first phase.
Right now, i'm able to show the question and when the user submits it, i'm also showing the answer but the other questions are also visible.I need to put in the loop my query but somewhere its missing.Could somebody please help me to fix my script and also i need to show the next button or link for the user to proceed to the next question.There are only 5 questions.
you can see the working example HERE
Thanks a million.
PHP-Code:
<?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}. The answer is $answer</td></tr>";
}
}
echo "</table></p>";
}
?>
Kommentar