//display student exam question based on subject number
$id=$_GET['id'];
$sql="SELECT MAX(eqid) FROM fyp_studentexamquestion where subjectnumber='$id'";
$result=mysql_query($sql) or die (mysql_error());
$maxid =mysql_fetch_row($result);
$maxid=$maxid[0];
$sql="SELECT * FROM fyp_studentexamquestion where subjectnumber='$id' and RAND()<(SELECT ((30/COUNT(*))*10) FROM fyp_studentexamquestion) ORDER BY RAND() LIMIT 30;";
$result=mysql_query($sql) or die (mysql_error());
$row = mysql_num_rows($result);
if($row > 0)
{
$a = 1;
$countrandom=1;
echo "<form method=\"POST\" action=\"";
echo htmlentities($_SERVER['PHP_SELF']);
echo "?id=";
echo $_GET['id'];
echo "\">";
while($row = mysql_fetch_assoc($result))
{
if($countrandom<=$counttotal) //compare total question and set question amount
{
if($a <= $maxid) // loop for question
{
echo "Question:".$a."<br />";
$a++ ;
}
echo $row["questions"]."<br />";
echo '<input type="radio" name="q' . $row["eqid"] . '_answer" value="A" />'.$row["answer1"].'<br />';
echo '<input type="radio" name="q' . $row["eqid"] . '_answer" value="B" />'.$row["answer2"].'<br />';
echo '<input type="radio" name="q' . $row["eqid"] . '_answer" value="C" />'.$row["answer3"].'<br />';
echo '<input type="radio" name="q' . $row["eqid"] . '_answer" value="D" />'.$row["answer4"].'<br />';
echo "<br />";
$_SESSION["q{$row["eqid"]}_correct_answer"] = $row["correctanswer"];
$countrandom++;
}
}
echo '<input type="submit" name="submit" class="buttonmodify" value="Submit Answers"/>'.'<br />';
echo '<input type="hidden" name="submitted" value="TRUE" />';
echo "<br />";
echo '</form>';
}
i can show every eqid into q[eqid]answer and answer by looping
but problem is. once i press the submitted button
i got no idea how to check with it.
as you can see im looping my while loop to get all the question and answer
but once the user click the radio button, how can it know the answer compare with correctanswer based on the eqid and display correct answer?
any suggestion ?
The value for epid is integer.
Example :
q1_answer = "A"
q1_answer = "B"
q1_answer ="C"
q1_answer ="D"
if i checked on D
how should it know?
and i wan compare the $row["answer"] with $row["correctanswer"]..
how could it done ><