php通过jquery测试脚本,将值传递到php文件


php test script via jquery, passing values to php file

主题不清楚,但ı会尝试解释。

ıam正在编写php测试测试脚本。ı想用jquery和php来做这件事。ıam在表格中列出问题和答案。

当你提交表格时,我通过$.ajax()将它们发送到test.php,并将它们与$_SERVER['QUERY_STRING']一起使用,但问题是如果有人没有选择答案,它不会传递空值。所以ı可以计算刚刚回答的问题。

这是我的代码:

$data=$_SERVER['QUERY_STRING'];   

我正在处理这些数据,但它不包括未回答的问题,所以我无法计算点。

html+php部分:

<form id="form1" name="form1" method="post" action="" class="form">
 <?php 
$sorgu=mysql_query("select * from question");
         $i=1;
                while($s=mysql_fetch_array($sorgu))
                {
                    $id=$s["id"];
                    $soru=$s["soru"];

                        $csorgu=mysql_query("select * from answer where q_id='$id'");
                        echo $i."-) ".$Question;
                        $i+=1;
                            while($c=mysql_fetch_array($csorgu))
                                {
                                    $soru_id=$c["soru_id"];
                                    $answer=$c["cevap"];
                                    $d=$c["d"];
                                    $cid=$c["id"];

                            ?>  
  <p>
    <label>
      <input type="radio" name="<?php echo $soru_id; ?>" value="<?php echo $cid; ?>"  />
      <?php echo $answer; ?></label>
    <label>
  </p>

<?php
}
                }
                ?>
                </form>

jquery:

$('#form1').submit(function(){
var myRadio = $("#form1 input[type='radio']:checked").val();
var form=($('#form1').serialize());

    $.ajax({
          type:"get",           
          url: "test.php?do=test",
          data:form,
          success: function(result){
            alert(result);
                                    }   
    });

你只需要我的积分计算系统:

$data=$_SERVER['QUERY_STRING'];

$data2=explode("&",$data); 
for ($i=0;$i<count($data2);$i++)
{
    $seri = explode("=", $data2[$i]);
    $seri_dizi[$i]=$seri[1];
}
unset($seri_dizi[0]);
$answer = array_count_values($seri_dizi);
@$false_answer=($answer["0"]);
$total_question=count($seri_dizi);
if($false_answer=" ") $false_answer=0;
$correct_answer=$total_question-$false_answer;

知道正确答案和错误答案,但不知道有多少问题没有答案

如果你有任何解决方案,我在这里。

最简单的方法可能是在您的问题中添加一个"未回答"的回答,默认情况下进行检查,如下所示:

例如:

 <input type="radio" name="my_question_1" value="0" checked/> Not answered
 <input type="radio" name="my_question_1" value="1"/> The first answer
 <input type="radio" name="my_question_1" value="2"/> The second answer