id field missing the continuity.
Posted: Wed May 21, 2003 7:04 am
hello,
this is a simple question and answer script sort of multiple choice.
When the user submits the answer for the first question, i show if the answer is correct or wrong and then proceed to next question.Now, the user submits the answer and now, i see the answer is displaying for the first one rather than the 2nd one and when i click on next question, i get the second question again rathern than the 3rd question.In total there are 5 questions in my table and i see the id field is missing the continuity.You can see the working example http://inkaytown.f2o.org/spiele/quizpage2.php
Could somebody please tell me where the error would be.
Thanks in advance
this is a simple question and answer script sort of multiple choice.
When the user submits the answer for the first question, i show if the answer is correct or wrong and then proceed to next question.Now, the user submits the answer and now, i see the answer is displaying for the first one rather than the 2nd one and when i click on next question, i get the second question again rathern than the 3rd question.In total there are 5 questions in my table and i see the id field is missing the continuity.You can see the working example http://inkaytown.f2o.org/spiele/quizpage2.php
Could somebody please tell me where the error would be.
Thanks in advance
Code: Select all
<?php
include("contentdb.php");
$id = $HTTP_GET_VARS["id"];
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="hidden" name="id" value="$id">";
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>";
$id = $id+1;
echo("<a href="quizpage2.php?id=$id">Next question</a>");
}
elseif ($$q == "")
{
echo "<tr><td>»you didn't select an answer. The answer is $answer</td></tr>";
$id = $id+1;
echo("<a href="quizpage2.php?id=$id">Next question</a>");
}
else {
echo "<tr><td>»you answered ${$q},which is wrong. The answer is $answer</td></tr>";
$id = $id+1;
echo("<a href="quizpage2.php?id=$id">Next question</a>");
}
}
echo "</table></p>";
}
?>