我正在开发一个在线考试系统。一切正常,但问题从第一个问题到最后一个问题被选中并显示。我想做以下事情:
选择问题并随机显示。
添加一个跳过按钮,以便学生可以跳过他们无法回答的任何问题,稍后会回滚给他们。
给回答时间留出时间,以便在时间结束时停止学生。
这是我选择问题的代码。
<!DOCTYPE html">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body{background-color:#f4fff8;}
#aq{
position:relative;
top:50px;
}
#st{
position:relative;
top:30px;
}
.btn{
background-color:#dedbb8;
color:#016e37;
text-shadow:3px 3px 3px gray;
box-shadow:3px 3px 3px gray;
height:40px;
text-align:center;
font-size:25px;
font-family:'Times New Roman';
font-weight:bold;
font-style:italic;
margin-top:2px;
border-radius: 2px;
}
.style8{
padding-top:5px;
font-size:20px;
}
#pt{
padding-top:20px;
}
h1{
position:relative;
color:green;
top:30px;
}
h2{
position:relative;
color:orange;
top:30px;
}
</style>
</head>
<body>
<?php
require_once("dbconnect.php");
include("header.php");
include("footer.php");
include("stdlogsession.php");
extract($_GET);
extract($_POST);
extract($_SESSION);
$student_id=$_SESSION['login_user'];
$student_id = stripslashes($student_id);
$student_id = mysqli_real_escape_string($db_conn,$student_id);
if(!empty($_GET['examid']))
{
$examid =$_GET['examid'];
}
// Selecting Database
$db = mysqli_select_db($db_conn,$mysql_database);
$rs=mysqli_query($db_conn,"select * from objquestions where exam_id='$examid'") or die('Error: ' .mysql_error($db_conn));
if(!isset($_SESSION['qn']))
{
$_SESSION['qn']=0;
}
if(!empty($_POST['submit'])=='Answer' && isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
if($ans==$row[8])
{
$remarks= "Correct";
$mark=$row[9];
} else {
$remarks= "Wrong";
$mark=0;
}
mysqli_query($db_conn,"insert into results(exam_id,student_id,quesNum,choice,remarks,mark) values ('$row[1]','$student_id','$row[2]', '$ans','$remarks','$mark')") or die(mysqli_error($db_conn));
$_SESSION['qn']=$_SESSION['qn']+1;
}
if($_SESSION['qn']>mysqli_num_rows($rs)-1)
{
$examN=mysqli_query($db_conn,"select examName from exampaper where exam_id='$examid'") or die('Error: ' .mysqli_error($db_conn));
$row = mysqli_num_rows($examN);
if ($row > 0) {
$rows=mysqli_fetch_assoc($examN);
$Enam=$rows['examName'];
}
echo "<center><h1>congrats! you have successfully finished your " .$Enam."</h1></center>";
echo "<center><h2> Click <a href=instresult.php>here</a> for your results </h2></center>";
unset($_SESSION['qn']);
exit();
}
if(!empty($_POST['submit'])=='Skip' && !isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
$_SESSION['qn']=$_SESSION['qn']+1;
}
$rs=mysqli_query($db_conn,"select * from exampaper where exam_id='$examid'") or die('Error: ' .mysql_error($db_conn));
$rows = mysqli_num_rows($rs);
while($rows=mysqli_fetch_row($rs))
{
echo "<center>";
echo "<table id=aq >";
echo "<tr><td>
<span class=style8>SUBJECT:</span></td>
<td class=style8>$rows[2]</td>
</tr>";
echo "<tr><td>
<span class=style8>EXAMINATION NAME:</span></td>
<td class=style8>$rows[1]</td>
</tr>";
echo "<tr><td>
<span class=style8>EXAMINATION DATE:</</span></td>
<td class=style8>$rows[3]</td>
</tr>";
echo "<tr><td>
<span class=style8>TOTAL TIME:</span></td>
<td class=style8>$rows[4]</td>
</tr>";
echo "<tr><td>
<span class=style8>INSTRUCTIONS:</span></td>
<td class=style8>$rows[5]</td>
</tr>";
echo "</table>";
echo "</center>";
}
$rs=mysqli_query($db_conn,"select * from objquestions where exam_id='$examid'") or die(mysqli_error($db_conn));
if($_SESSION['qn']>mysqli_num_rows($rs)-1)
{
unset($_SESSION['qn']);}
echo "<center>";
echo "<table id=st>";
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
echo "<form name=myfm method=post action=exam.php>";
$n=$_SESSION['qn']+1;
echo "<tR ><td id=pt><span class=style8>Quetion ". $n .": $row[3]</style></td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=A>$row[4]</td></tr>";
echo "<tr><td class=style8> <input type=radio name=ans value=B>$row[5]</td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=C>$row[6]</td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=D>$row[7]</td></tr>";
echo "<tr><td><input class=btn type=submit name=submit value='Answer'> <input align=right class=btn type=submit name=submit value='Skip'></td></tr></form>";
echo "</table>";
echo "</center>";
?>
</body>
</html>