比较数组以计算等级

时间:2015-04-11 10:02:16

标签: php

我的student.php页面:从数据库中随机显示多个​​选项的问题

 <form name="f1" id=f1 method="get" action="submittingquiz.php">
        <?php
        $correct=array();

      $query=  mysql_query("select 
     question_number,question_description,correctanswer_id from 
     quizzesbankofquestion where course_code='MATH220' && quiz_level='1' && 
     level_of_difficulty='1' ORDER BY RAND() LIMIT 3");
     if (!$query) die ("Database access failed: " . mysql_error());
       $row=  mysql_num_rows($query); 
      if($row!=0){

      while($questions=  mysql_fetch_array($query)){
          $correct=array($questions[2]);
          $_SESSION['array']=$correct;
        echo "<table>
         <tr><td> $questions[0]</td>
                  <td>$questions[1]</td> </tr>";

          $choices=  mysql_query("select choices_id,choices_descriptions
        from quiz_choices where course_code='MATH220' && 
        question_number='$questions[0]'ORDER BY RAND() ");

          if (!$choices) die ("Database access failed: " . mysql_error());

          while($questionchoices=  mysql_fetch_array($choices)){

             echo "<tr><td><input type='radio' value='$questionchoices[0]' 
          name='$questions[0]'/>$questionchoices[1]</td></tr></table>";}
           }}?>
    <input type="submit" id="btn_submit" name="btn_submit" value="submit" />
      </form>

Submitting.php

  <?php

    require_once 'connect.php';
    session_start();
    $numCorrect = 0;
    $answers=array();

    if(isset($_SESSION['array'])){
         print_r ($_SESSION['array']); //it is not printing the same array as $correct,It is only printing one element
        $correct=$_SESSION['array'];

    foreach($correct as $key=>$val){
       $answers=$_GET['$questions[0]'];//trying to get the values of the radio buttons and store it in array
        print_r($answers);// displaying Array word only

   if($val = $answers[$key]){
   $numCorrect++;
    }
     }  }?>

数组会话显示不一样,我也不知道如何填充数组中单选按钮的值。我正在尝试比较正确的答案。 提前谢谢

2 个答案:

答案 0 :(得分:0)

你想要javascript&#39; s setTimeout()

此答案提供了更多信息:JavaScript.setTimeout

答案 1 :(得分:0)

此脚本将在几秒钟内倒计时,并在完成后重定向到新页面

 <html>
<head>
<title>test countdown</title>   
</head>
<body>

<span id="counter">10</span>


 <script type="text/javascript">
        function countdown() {
            var i = document.getElementById('counter');
                if (parseInt(i.innerHTML)<=0) {
                   location.href = 'new.html';
                }
                i.innerHTML = parseInt(i.innerHTML)-1;
            }
            setInterval(function(){ countdown(); },1000);
    </script>

</body>
</html>