1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| foreach ($flux->questions->$question_type_label as $questions_list){
$question=$questions_list-> direction;
$status=$questions_list['status'];
$question_id=$questions_list['id']; // id encodé
$question = addslashes($question);
$sql = "SELECT id FROM quiz_questions WHERE question_id ='$question_id' and quiz_liste_id='$survey_id'"; // Changement dans le select pour éviter de sélectionne un id qui sincrémente à chaque fois
// on compte le nombre de résultats
$q = $bdd->query($sql);
$rows = $q->fetchAll();
$res = count($rows);
if($res!=0) // La question existe déjà en base on ne va pas donc la recréer
{
//temp
echo "Question already exist<br>";
$stmt = $bdd->query($sql);
$sql_result = $stmt->fetch(PDO::FETCH_ASSOC);
$question_id = $sql_result['id'];
$sql = "UPDATE quiz_questions SET question_direction='$question' WHERE question_id='$question_id'"; // Changement effectué
$bdd->exec($sql);
}
else
{
$sql = "INSERT INTO quiz_questions (id,question_id,question_type_id,quiz_liste_id,question_direction)"
. " VALUES"
. "('','$question_id','$question_type_id','$survey_id','$question')";
$bdd->exec($sql);
// on récupère l'id du quiz qui vient d'être généré
$question_id = $bdd->lastInsertId();
//temp
echo "New question with ID ".$question_id." added<br>";
}
if ($question_type_label=="essayQuestion") // On teste ensuite sous chaque if les différents types de questions
{
$user_answer=$questions_list-> userAnswer;
$user_answer = addslashes($user_answer);
$sql = "INSERT INTO survey_results (id_results,question_id,survey_id, user_id,survey_date,question_status,timing_id,user_answer)"
. "VALUES"
. "('','$question_id','$survey_id','$user_id','$curdate','$status','$timing_id','$user_answer')";
$bdd->exec($sql);
}
else
{
if($question_type_label=="yesNoQuestion")
{
$user_answer=$questions_list-> answers[@userAnswerIndex];
if($user_answer == 0)
{
$user_answer = "Yes";
}
else
{
$user_answer = "No";
}
$user_answer = addslashes($user_answer);
$sql = "INSERT INTO survey_results (id_results,question_id,survey_id, user_id,survey_date,question_status,timing_id,user_answer)"
. "VALUES"
. "('','$question_id','$survey_id','$user_id','$curdate','$status','$timing_id','$user_answer')";
$bdd->exec($sql);
} else
{
if($question_type_label=="pickOneQuestion")
{
$user_answer=$questions_list-> answers[@userAnswerIndex];
//echo "user_answer : " . $user_answer;
$quiz_answer=$questions_list-> answers-> answer[(int)$user_answer];
//$quiz_answer=$questions_list-> answers-> answer["1"];
/*echo "quiz_answer : " . $quiz_answer;
$test=$questions_list-> answers;
print_r($test);
echo"<br/>";*/
//$user_answer=$quiz_answer[$user_answer];
//$user_answer = addslashes($user_answer);
$sql = "INSERT INTO survey_results (id_results,question_id,survey_id, user_id,survey_date,question_status,timing_id,user_answer)"
. "VALUES"
. "('','$question_id','$survey_id','$user_id','$curdate','$status','$timing_id','$quiz_answer')";
$bdd->exec($sql);
} |