Log in

View Full Version : help needed for a an online exam code.



sukanya.paul
05-02-2007, 03:17 AM
hi,
i'm new at php n doin a proj without much of help.
i hv to create a form for online exam.
i hv a table called question which has questions for diff sections of tests quantitative,analytical ,english and technical.
the fields in the table are:`id`, `level`, `section`, `quest`, `opt1`, `opt2`, `opt3`, `opt4`, `ans`
id-quest id,
level-level of difficulty (easy,medium and hard)
section-quantitative,analytical ,english and technical
quest-the question,
opt- various option and ans-the correct answer.

in my form 10 questions hv to randomly displayed with the 4 options havin radio buttons.
every 10 sec the question will change.(i hv used meta refresh tag for this)
the form wil hv 2 buttons confirm and next. on pressing confirm the ans wil be verified and score will be updated while on pressin next next question will be displayed. after 10 questions for a section next set of ques for diff section shud be displayed.

MY PROB
1. i am not able to get the logic of combining the refresh with next button by keepin the count of quest.
2.whn i use for the same question is bein displayed 10 times instead of 10 diff questions being displayed.
help will be appreciated.
thanks in advance..suk

my incomplete code :( :confused:
<html>
<body>
<meta http-equiv="refresh" content="15">
<?php
include 'db.php';
$maximum=mysql_query("select MAX(id) as max from question");
$chk = mysql_num_rows($maximum);
$u = mysql_fetch_array($maximum);
$max=$u['max'];
//echo "maximum=" . $max;
$minimum=mysql_query("select MIN(id) as min from question");
$chk1 = mysql_num_rows($minimum);
$r = mysql_fetch_array($minimum);
$min=$r['min'];
//echo "minimum=" . $min. "<br>";
$random_digit=rand($min,$max);
echo $random_digit;
$count='0';
//for ( $counter = 1; $counter <= 10; $counter += 1)
while (count <= 10);
{
$sql=mysql_query("SELECT * FROM question WHERE id='$random_digit'");
$num=mysql_num_rows($sql);
if ($num>0)
$valid=true;
if ($valid)
{
echo "<table width='95%' border='2'>
<tr>
<th>#</th>
<th>ID</th>
<th>QUESTION</th>
<th>OPTION 1</th>
<th>OPTION 2</th>
<th>OPTION 3</th>
<th>OPTION 4</th>
<th>ANSWER</th>
</tr>";
while($row = mysql_fetch_array($sql))
{
echo "<tr>";?>
<?
echo "<td>" . $row['id'] . "</td>";
echo "<td>" .$row['quest'] . "</td>" ."<br>";
?>
<td align="center"> <input type="radio" name="group1" id="<?=$row[id]?>" value="<?=$row[id]?>" /> </td>
<?
echo "<td>" . $row['opt1'] . "</td>" . "<br>";?>
<td align="center"> <input type="radio" name="group1" id="<?=$row[id]?>" value="<?=$row[id]?>" /> </td>
<? echo "<td>" . $row['opt2'] . "</td>" . "<br>";?>
<td align="center"> <input type="radio" name="group1" id="<?=$row[id]?>" value="<?=$row[id]?>" /> </td>
<? echo "<td>" . $row['opt3'] . "</td>" . "<br>";?>
<td align="center"> <input type="radio" name="group1" id="<?=$row[id]?>" value="<?=$row[id]?>" /> </td>
<? echo "<td>" . $row['opt4'] . "</td>";
//echo "<td>" . $row['ans'] . "</td>";
echo "</tr>";
}
echo "</table>";
}

count += 1;



}


?>
</body>
</html>

lettie_dude
05-03-2007, 09:59 AM
Just looking at this quickly it would appear you need to put your random number generator into your while loop so it generates a new random number each time it loops.