php:为测验添加进度条

时间:2018-07-30 08:09:38

标签: javascript mysql pdo progress-bar

我是php的新手。我选择多项测验,从MySQL数据库中检索问题并将其显示给用户,并将所选的选择保存到数据库中,我想要做的就是添加用户到达问题10时测验的进度条。进度条更改为20%,依此类推..。我使用问题ID来检索我在网上搜索的问题,但找不到有用的资源我正在尝试做.. 将提供任何帮助

这是 exam.php

   <body>

<?Php
require "config0.php";
$count=$dbo->prepare("select * from questions where question_id=1 ");
if($count->execute()){
$row = $count->fetch(PDO::FETCH_OBJ);
}
echo "
<div id='maindiv' class='maindiv'>
<form id='f1'>
        <table>
        <tr><th>
        <input type='' id=question_id value=$row->question_id>
        </th></tr>
        <tr><th>
        <h4 id='q1'>$row->question</h4>
        </th></tr>

        <tr><td>
              <input type='radio' name='options' id='opt1' value='1' > <label for='opt1' class='lb'>$row->opt1</label>
        </td></tr>
        <tr><td>
              <input type='radio' name='options' id='opt2' value='2' >  <label for='opt2' class='lb'>$row->opt2</label>
        </td></tr>

        <tr><td>
              <input type='radio' name='options' id='opt3' value='3' >  <label for='opt3' class='lb'>$row->opt3</label>

        </td></tr>
        <tr><td>
              <input type='radio' name='options' id='opt4' value='4' >  <label for='opt4' class='lb'>$row->opt4</label>
        </td></tr>
        <tr><td>
              <input type='radio' name='options' id='opt5' value='5' >  <label for='opt5' class='lb'>$row->opt5</label>
        </td></tr>
        <tr><td>
              <input type='radio' name='options' id='opt6' value='6' >  <label for='opt6' class='lb'>$row->opt6</label>
        </td></tr>

        </table>
</form>
</div>
<div id='progress_bar'></div>

";
?>
<script>
   $(document).ready(function() {



$("input:radio[name=options]").click(function() {
$('#maindiv').hide('slide', {direction: 'left'}, 2000);
$.post( "examck.php", {"option_no":$(this).val(),"question_id":$("#question_id").val()},function(return_data,status){

if(return_data.next=='T'){

$("#question_id").val(return_data.data.question_id);
$('#q1').html(return_data.data.q1);
$('label[for=opt1]').html(return_data.data.opt1);
$('label[for=opt2]').html(return_data.data.opt2);
$('label[for=opt3]').html(return_data.data.opt3);
$('label[for=opt4]').html(return_data.data.opt4);
$('label [for = opt5]').html(return_data.data.opt5);
$('label [for = opt6]').html(return_data.data.opt6);



}
else{$('#maindiv').html("Thank you for taking the Quiz the result will be sent to your email ");
    $.ajax({ url: 'score.php' });
        var link = $("<a href ='registrationForm.php'>...close</a>");
        $('#maindiv').append(link);


        }

},"json"); 
$("#f1").delay(1000);
$("#f1")[0].reset();
 $('#maindiv').show('slide', {direction: 'right'}, 1000);


</script>
</body>

这是从数据库收集数据

的脚本
<?Php
session_start();
error_reporting(E_ALL); 
ini_set('display_errors', 1);
require "config0.php";




$question_id=$_POST['question_id'];


$option_no=$_POST['option_no']; // User choice

//////// Collected from databse ///////
$question_id=$question_id+1;



$no_questions = $dbo->query("select count(question) from questions
left join servey_question on questions.question_id = servey_question.question_id where servey_id = 'serv01' ")->fetchColumn();

if($question_id > $no_questions) {
    $next='F'; // Flag is set to display thank you message
    echo json_encode(array("next"=>$next));
} else {
    $next='T'; // Flag is set to display next question
    $count=$dbo->prepare("select * from questions where question_id=$question_id");
    $count->execute();
    $row = $count->fetch(PDO::FETCH_OBJ);
    $main= array("data"=>array(
        "q1"=>"$row->question",
        "opt1"=>"$row->opt1",
        "opt2"=>"$row->opt2",
        "opt3"=>"$row->opt3",
        "opt4"=>"$row->opt4",
        "opt5"=>"$row->opt5",
        "opt6"=>"$row->opt6",
        "question_id"=>"$question_id",
        "category_id"=>"$row->category_id"
    ),
    "next"=>"$next");
    echo json_encode($main);
}

0 个答案:

没有答案