如何计算php中在线考试系统的总分

时间:2013-12-16 11:43:32

标签: php html mysql

我正在开发简单的在线考试系统。添加问题管理员时输入该问题的正确分数和负分数。但我的问题是如何得到每个问题和总分的正确和负分数。我无法得到结果。 下面的代码是提交测试 的 submittest.php

<?php
require_once("db.php");
session_start();
$tot=0;
$correct=0;
$wrong=0;
$ques='';
$answered=0;
$wrong_answered=0;
$resgiterno=$_POST['registerno'];
 //$id= $_SESSION['id'];



foreach($_POST as $key=>$value)
{
  $id=substr($key,7);
    $tot++;

 $answer=implode(",",$value);


 //if(dbSelect("questions","*","correct_option='$answer' and id='$id'",""))
 if($score_sql=mysql_query("select * from questions where correct_option='$answer' and id='$id'"))
 {
  $score=mysql_fetch_array($score_sql);


   $correct=$correct+$score['correct_score'];   
   $wrong=$wrong+$score['negative_score'];
//echo $val;
  $ques.=$id.",";

  }


}


$total_marks=$correct-$wrong;
//echo "total score is $total_marks";


echo "Congratulations you have Completed the Exam";


?>

此处如何显示问题代码

<div class="que_box_left"><div class="d1"><div class="option">a)</div><input name="answer_<?php echo $question['id']?>[]" type="checkbox" value="option_a" class="mar_ri" /></div>
<div class="d2"><?php echo $question['option_a'] ?></div></div>
<div class="que_box_left"><div class="d1"><div class="option">b)</div><input name="answer_<?php echo $question['id']?>[]" type="checkbox" value="option_b" class="mar_ri" /></div>
<div class="d2"><?php echo $question['option_b']?></div></div>
<div class="clear"></div>

<div class="que_box_left"><div class="d1"><div class="option">c)</div><input name="answer_<?php echo $question['id']?>[]" type="checkbox" value="option_c" class="mar_ri" /></div>
<div class="d2"><?php echo $question['option_c']?></div></div>
<div class="que_box_left"><div class="d1"><div class="option">d)</div><input name="answer_<?php echo $question['id']?>[]" type="checkbox" value="option_d" class="mar_ri" /></div>
<div class="d2"><?php echo $question['option_d']?>
</div>

这里我如何将数据发送到上面的代码submit-test.php

$('.form_test_submit').live("click",function(){
    $.post("submit-test.php?testname="+testname,$('.form_test').serialize(),function(data){    
     alert(data);

    if(data=='Congratulations you have Completed the Exam')
      window.location.assign("results.php");
      /*
     else 
     window.location.assign("level.php?sid=<?php echo $student['sid'] ?>&eid=<?php echo $eid ?>&subid=<?php echo $subid ?>");
   */ });
   return false;
});

通过该代码,我无法获得精确结果。请帮我。在此先感谢

1 个答案:

答案 0 :(得分:0)

您可以使用会话。在提交真实答案时使用session ++和错误使用会话 - 如果你想显示错误和正确答案,你可以使用两个会话一个用于错误,另一个用于正确。在提交真实答案时使用right_session ++和错误使用wrong_sesssion ++。