我有一个问题,我不知道如何用计时器进行测验... 我向您解释了我想做什么:
测验是多项选择题形式的测验。
用户在“命题”表中看到一个随机抽取的问题,他还看到4个选择的答案,当他选择一个答案并单击“发送”时,他将答案记录在数据库中,并保存了计时器的值。 精密计时器工作正常,插入答案也有效,但是要在数据库中注册的精密计时器的值始终为0。
<?php
require_once('inc/init.inc.php');
$page = 'Jouer';
extract($_SESSION['users']);
$id_loaba=$_GET['id'];
$limite=1;
$pagee=$_GET['page'];
$debut=($pagee-1)*$limite;
$req= $pdo -> query("select * from test,proposition where
test.id_loaba=".$id_loaba." and test.id_propo= proposition.id_propo
LIMIT $debut,$limite");
while($data=$req -> fetch(PDO::FETCH_ASSOC)){
echo' <form action="" method="post">';
echo $data['question'].'<br />';
echo $data['id_propo'].'<br />';
echo '<input type="radio" name="rep"
value="'.$data["rep1"].'+'.$data['id_propo'].'"
/>'.$data['rep1'].'<br />';
echo '<input type="radio" name="rep"
value="'.$data["rep2"].'+'.$data['id_propo'].'"
/>'.$data['rep2'].'<br />';
echo '<input type="radio" name="rep"
value="'.$data["rep3"].'+'.$data['id_propo'].'"
/>'.$data['rep3'].'<br />';
echo '<input type="radio" name="rep"
value="'.$data["rep4"].'+'.$data['id_propo'].'"
/>'.$data['rep4'].'<br /><br />';
}
$nbpage=7; //calcule de nombre de page
if ($pagee==1){
echo '<a href="jouerJeu.php?page=$next&id=$id_loaba"><input
type="submit" id="arret" value="Envoyer"> </a>';
$_SESSION['pageencour']=2;
}else if ($pagee < 7){
echo '<a href="jouerJeu.php?page=$next&id=$id_loaba"><input
type="submit" id="arret" value="Envoyer"> </a>';
$next=$pagee+1;
}
else{
echo'<a href="score.php"><input type="submit" id="arret"
value="Envoyer"> </a>';
}
echo'</form>';
?>
<label><?php echo $lastname?></label></br>
<span id="mySpan" style="font-size: 80px;">20</span>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script type="text/javascript">
function decrementer() {
if ( mySpan.innerHTML > 0 ) {
mySpan.innerHTML-- ;
setTimeout(decrementer, 1000);
}
}
setTimeout(decrementer, 1000) ;
var element = document.getElementById('arret');
element.onclick = function() {
var chrono=mySpan.innerHTML;
$.ajax({
type: "GET",
data: {chrono : chrono},
success: function(data)
{
console.log(chrono);
}
});
};
</script>
<?php
if(isset($_GET['chrono'])){
$chrono=$_GET['chrono'];
}else{
$chrono=0;
}
if($_POST){
echo $chrono;
// INSERTION DES INFOS DANS LA BDD :
if(isset($_POST['rep'] ) ){
$var= $_POST['rep'];
$pos = strpos($var, '+', 1);
$id_quest=substr($var, $pos, strlen($var));
$rep= substr($var, 0, $pos);
$resultat = $pdo -> prepare("INSERT INTO rep_loaba
(id_quest,id_joueur,rep,id_loaba,score) VALUES
(:id_quest,:id_joueur,:rep, :id_loaba,:score)");
//INT
$resultat -> bindParam(':id_quest', $id_quest, PDO::PARAM_INT);
$resultat -> bindParam(':id_joueur', $id_user, PDO::PARAM_INT);
$resultat -> bindParam(':rep', $rep, PDO::PARAM_STR);
$resultat -> bindParam(':id_loaba', $id_loaba, PDO::PARAM_INT);
$resultat -> bindParam(':score', $chrono, PDO::PARAM_INT);
if($resultat -> execute()){
$id_insere = $pdo -> lastInsertId();
$page=$_GET['page'];
$next=$page+1;
header('location:jouerJeu.php?page='.$next.'&id='.$id_loaba);
}
else{
$msg .= '<div class="erreur">Erreur dans la requête !! </div>';
}
}else{
header('location:jouerJeu.php?page='.$next.'&id='.$id_loaba);
}
}
?>