计时器结束后显示下一个测验问题

时间:2019-12-08 06:05:11

标签: javascript php jquery

我正在尝试创建一个测验站点。它几乎已经完成,但是我在计时器选项中面临问题。我正在为每个问题显示计时器,当计时器结束时,它停留在同一页面/问题上。 我想在计时器到期后显示下一个问题。和在最后一个问题之后会显示结果页面

希望尽快获得解决方案。


<body>

<?php
include("header.php");

echo '<div class="timer"><b><div id="countdown"></div>
<div id="notifier"></div></b></div>';
$query="select * from mst_question";

$rs=mysql_query("select * from mst_question where test_id=$tid",$cn) or die(mysql_error());
if(!isset($_SESSION[qn]))
{
    $_SESSION[qn]=0;
    mysql_query("delete from mst_useranswer where sess_id='" . session_id() ."'") or die(mysql_error());
    $_SESSION[trueans]=0;

}
else
{   
        if($submit=='Next Question' && isset($ans))
        {
                mysql_data_seek($rs,$_SESSION[qn]);
                $row= mysql_fetch_row($rs); 
                mysql_query("insert into mst_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());
                if($ans==$row[7])
                {
                            $_SESSION[trueans]=$_SESSION[trueans]+1;
                }
                $_SESSION[qn]=$_SESSION[qn]+1;
        }
        else if($submit=='Get Result' && isset($ans))
        {
                mysql_data_seek($rs,$_SESSION[qn]);
                $row= mysql_fetch_row($rs); 
                mysql_query("insert into mst_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());
                if($ans==$row[7])
                {
                            $_SESSION[trueans]=$_SESSION[trueans]+1;
                }
                echo "<h1 class=head1> Result</h1>";
                $_SESSION[qn]=$_SESSION[qn]+1;
                echo "<Table align=center><tr class=tot><td>Total Question<td> $_SESSION[qn]";
                echo "<tr class=tans><td>True Answer<td>".$_SESSION[trueans];
                $w=$_SESSION[qn]-$_SESSION[trueans];
                echo "<tr class=fans><td>Wrong Answer<td> ". $w;
                echo "</table>";
                mysql_query("insert into mst_result(login,test_id,test_date,score) values('$login',$tid,'".date("d/m/Y")."',$_SESSION[trueans])") or die(mysql_error());
                echo "<h1 align=center><a href=review.php> Review Question</a> </h1>";
                unset($_SESSION[qn]);
                unset($_SESSION[sid]);
                unset($_SESSION[tid]);
                unset($_SESSION[trueans]);
                exit;
        }
}
$rs=mysql_query("select * from mst_question where test_id=$tid",$cn) or die(mysql_error());
if($_SESSION[qn]>mysql_num_rows($rs)-1)
{
unset($_SESSION[qn]);
echo "<h1 class=head1>Some Error  Occured</h1>";
session_destroy();
echo "Please <a href=index.php> Start Again</a>";

exit;
}

mysql_data_seek($rs,$_SESSION[qn]);
$row= mysql_fetch_row($rs);

echo "<form name=myfm method=post action=quiz.php>";
echo "<table width=100%> <tr> <td width=30>&nbsp;<td> <table border=0>";
$n=$_SESSION[qn]+1;
echo "<tR><td><span class=style2>Que ".  $n .": $row[2]</style>";
echo "<tr><td class=style8><input type=radio name=ans value=1>$row[3]";
echo "<tr><td class=style8> <input type=radio name=ans value=2>$row[4]";
echo "<tr><td class=style8><input type=radio name=ans value=3>$row[5]";
echo "<tr><td class=style8><input type=radio name=ans value=4>$row[6]";

if($_SESSION[qn]<mysql_num_rows($rs)-1)
echo "<tr><td><input type=submit name=submit value='Next Question'></form>";
else
echo "<tr><td><input type=submit name=submit value='Get Result'></form>";
echo "</table></table>";
?>


<script type="text/javascript">
(function () {
  function display( notifier, str ) {
    document.getElementById(notifier).innerHTML = str;
  }

  function toMinuteAndSecond( x ) {
    return Math.floor(x/60) + ":" + (x=x%60 < 1 ? 0 : x);
  }

  function setTimer( remain, actions ) {
    var action;
    (function countdown() {
       display("countdown", toMinuteAndSecond(remain));
       if (action = actions[remain]) {
         action();
       }
       if (remain > 0) {
         remain -= 1;
         setTimeout(arguments.callee, 1000);
       }
    })(); // End countdown
  }

  setTimer(45, {
     0: function () { display("notifier", "Time is up!");       }
  });
})();

</script>
</body>

0 个答案:

没有答案