if(!isset($_GET['start'])){
$_GET['start'] = "undefined";
}
$start=$_GET['start'];// To take care global variable if OFF
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$startpos = ($start -0);
$limit = 1;
// No of records to be shown per page.
$currentpos = $startpos + $limit;
$back = $startpos - $limit;
$next = $startpos + $limit;
$countquery=" SELECT * FROM quiz ";
$countresult=mysql_query($countquery);
echo mysql_error();
$totalrecords=mysql_num_rows($countresult);
//$quiz_table = mysql_query("select * from quiz Limit 1");
?>
<form method="POST" action="" onclick="">
<table>
<?php
$quiz_table=" SELECT * FROM quiz ORDER BY qid limit $startpos, $limit ";
$result=mysql_query($quiz_table);
echo mysql_error();
while ($row = mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo "$row[qid]"; ?></td>
<td><?php echo "$row[Question]"; ?></td>
</tr>
<tr>
<td><input type="radio" name="a" id="a" value="a"/> <?php echo "$row[opt1]"; ?></td>
<td><input type="radio" name="a" id="a" value="b"/> <?php echo "$row[opt2]"; ?></td>
<td><input type="radio" name="a" id="a" value="c"/> <?php echo "$row[opt3]"; ?></td>
<td><input type="radio" name="a" id="a" value="d"/> <?php echo "$row[opt4]"; ?></td>
</tr>
<tr>
<td><!--<input type="submit" name="smt" value="check"/>-->
<?php
if($back >=0) {
print "<a href='onlineexam.php?start=$back'><font face='Verdana' size='2'><input type='button' name='prev' value='PREV'></font></a>";
}
//echo "</td><td align='right' width='10%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($currentpos < $totalrecords) {
print "<a href='onlineexam.php?start=$next'><font face='Verdana' size='2'><input type='button' name='nxt' value='NEXT'></font></a>";
}
?></td>
<td><input type="submit" name="smt" value="Finish"/></td>
</tr>
<?php
}
$quiz_table="SELECT * from quiz";
$result=mysql_query($quiz_table);
while ($row = mysql_fetch_array($result))
{
$id=$row['qid'];
$ques=$row['Question'];
$op1=$row['opt1'];
$op2=$row['opt2'];
$op3=$row['opt3'];
$op4=$row['opt4'];
$crt=$row['woptcode'];
if(isset($_POST['smt'])){
$ans= $_POST['a'];
if(isset($_POST['a'])){
if($crt == $ans ){
$mark=0;
$mark=$mark+1;
mysql_query("INSERT INTO stuans(qid,Question,opt1,opt2,opt3,opt4,woptcode,stuanswer,mark)VALUES('$id','$ques','$op1','$op2','$op3', '$op4','$crt','$ans','$mark')");
}else{
$mark=0;
mysql_query("INSERT INTO stuans(qid,Question,opt1,opt2,opt3,opt4,woptcode,stuanswer,mark)VALUES('$id','$ques','$op1','$op2','$op3', '$op4','$crt','$ans','$mark')");
}
}
}
}