我设法设置了一个在线考试网站的时间。这里的所有资源都有很大的帮助!但是,我在计时器中面临着更加艰巨的任务。出于某些原因,很明显我不知道,单击“下一个问题”提交输入后,它将重置。怎么了?
首先,我将javascript代码添加到了显示计时器的主页上,然后在网上某个地方发现包含它作为标头就可以解决问题。哪个没有用,或者我没有正确执行。我对此知识不多。
Header.php
下方的javascript文件
<?php $dateFormat="d F Y -- g:i a" ; $targetDate=t ime() + (1*60);//Change the 25 to however many minutes you want to countdown $actualDate=t ime(); $secondsDiff=$ targetDate - $actualDate; $remainingMinutes=f loor(($secondsDiff-($remainingDay*60*60*24)- ($remainingHour*60*60))/60); $remainingSeconds=f loor(($secondsDiff-($remainingDay*60*60*24)- ($remainingHour*60*60))-($remainingMinutes*60)); $actualDateDisplay=d ate($dateFormat,$actualDate); $targetDateDisplay=d ate($dateFormat,$targetDate); ?>
<script type="text/javascript">
var minutes = <? php echo $remainingMinutes; ?>
var seconds = <? php echo $remainingSeconds; ?>
function setCountDown() {
seconds--;
if (seconds < 0) {
minutes--;
seconds = 59
}
if (minutes < 0) {
hours--;
minutes = 59
}
document.getElementById("remain").innerHTML = minutes + " m: " + seconds + "
s ";
setTimeout("setCountDown()", 1000);
if (minutes == '00' && seconds == '00') {
seconds = "00";
clearTimeout();
document.getElementById("myfm").submit();
}
}
</script>
test.php
又是以下主页:
<?php $query="select * from tbl_questions" ; $rs=mysqli_query($con, "select * from tbl_questions where test_id=$tid and
course_id=$sid") or die(mysqli_error()); if(!isset($_SESSION[ 'qn'])) { $_SESSION[ 'qn']=0 ; mysqli_query($con, "delete from tbl_answers where sess_id='" . session_id() . "'") or die(mysqli_error()); $_SESSION[ 'trueans']=0; } else { if($submit=='Next Question' && isset($ans)) { mysqli_data_seek($rs,$qn); $row=m ysqli_fetch_row($rs); $q=mysqli_real_escape_string($con,$row[1]); $r=mysqli_real_escape_string($con,$row[4]); $s=mysqli_real_escape_string($con,$row[5]); $t=mysqli_real_escape_string($con,$row[6]); $u=mysqli_real_escape_string($con,$row[7]); mysqli_query($con, "insert into tbl_answers(sess_id, course_id, test_id,
que_des, ans1,ans2,ans3,ans4,true_ans,your_ans) values
('".session_id(). "', $sid, $tid,'$q','$r','$s','$t',
'$u','$row[8]','$ans')") or die(mysqli_error($con)); if($ans==$row[8]) { $_SESSION[ 'trueans']=$_SESSION[ 'trueans']+1; } $_SESSION[ 'qn']=$_SESSION[ 'qn']+1; } else if($submit=='Final Submit' && isset($ans)) { mysqli_data_seek($rs,$_SESSION[ 'qn']); $row=m ysqli_fetch_row($rs); $q=mysqli_real_escape_string($con,$row[1]); $r=mysqli_real_escape_string($con,$row[4]); $s=mysqli_real_escape_string($con,$row[5]); $t=mysqli_real_escape_string($con,$row[6]); $u=mysqli_real_escape_string($con,$row[7]); mysqli_query($con, "insert into tbl_answers(sess_id, course_id, test_id,
que_des, ans1,ans2,ans3,ans4,true_ans,your_ans) values
('".session_id(). "', $sid, $tid,'$q','$r','$s','$t',
'$u','$row[8]','$ans')") or die(mysqli_error()); if($ans==$row[8]) { $_SESSION[ 'trueans']=$_SESSION[ 'trueans']+1; } echo "<div class='col-12 col-md-8 test-form'>"; echo "<h2> Result</h2>"; $_SESSION[ 'qn']=$_SESSION[ 'qn']+1; echo "<h1>Assessment Score:<td>"; echo "</h1>"; echo "<p class=sixteen>You Scored: </p>"; echo "<h1 class=green>" .$_SESSION[ 'trueans']; echo "</div>"; mysqli_query($con, "insert into
tbl_results(student_mat_no,course_id,test_id,scores,created_at)
values('$student_mat_no',$sid,$tid,".$_SESSION[ 'trueans']. ",'".date( "d/m/Y"). "')") or die(mysqli_error()); echo "<p class='btn btn-info home'><a href=index.php> Home</a> </p>"; echo "<p class='btn btn-danger logout'><a href=logout.php> Logout</a>
</p>"; unset($_SESSION[ 'qn']); unset($_SESSION[ 'sid']); unset($_SESSION[ 'tid']); unset($_SESSION[ 'trueans']); exit; } } $rs=mysqli_query($con, "select * from tbl_questions where test_id=$tid") or die(mysqli_error()); $total=m ysqli_num_rows($rs); if($_SESSION[ 'qn']>mysqli_num_rows($rs)-1) { unset($_SESSION['qn']); echo "
<h1 class=head1>Error Occured</h1>"; session_destroy(); echo "Lets <a href=index.php> Start Over</a>"; exit; } mysqli_data_seek($rs,$_SESSION['qn']); $row= mysqli_fetch_row($rs); echo "
<div class='col-12 col-md-8 test-form'>"; echo "
<form id=myfm name=myfm method=post action=test.php>"; include ('header.php'); echo "
<div id=remain>$remainingMinutes minutes, $remainingSeconds seconds"; echo "</div>"; $n=$_SESSION['qn']+1; echo "
<div class=current>Question ". $n ." of ". $total. " : ". $row[1] . "
</div>"; echo "</p>"; echo "
<ul class=choices>"; echo "
<li>
<input name=ans type=radio value=1>$row[4]</li>"; echo "
<li>
<input name=ans type=radio value=2>$row[5]</li>"; echo "
<li>
<input name=ans type=radio value=3>$row[6]</li>"; echo "
<li>
<input name=ans type=radio value=4>$row[7]</li>"; echo "</ul>"; echo "
<input class='btn btn-primary' type=submit name=submit value='Next
Question'>"; echo "
<input class='btn btn-danger' type=submit name=submit value='Final
Submit'>
</form>"; echo "</div>"; ?>
我希望这个计时器停止重新设置进入时间,或者在下一个问题中,超时时错误可能不是自动提交,但这又是一天了