From 2d90140afa2add2cb7bf95ef80fc0530391c03a8 Mon Sep 17 00:00:00 2001 From: Leander Date: Mon, 3 Apr 2017 13:52:31 +0200 Subject: [PATCH] T201704031352 --- Question.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Question.php b/Question.php index 495adaa..99e11a2 100644 --- a/Question.php +++ b/Question.php @@ -13,13 +13,12 @@ class Question { private $question; private $answers; - private $correct_answer_position; private $category_id; private $category; - function __construct($db, $id) { + function __construct($db, $uid, $qid) { $question_details = $db->query('SELECT "question", "answer0", "answer1", "answer2", "answer3", "Categories_ID" - FROM "Questions" WHERE "ID" = $1', array($id))['data'][0]; + FROM "Questions" WHERE "ID" = $1', array($qid))['data'][0]; $q = $question_details['question']; $a0 = $question_details['answer0']; $a1 = $question_details['answer1']; @@ -29,19 +28,17 @@ class Question $c = $db->query('SELECT "name" FROM "Categories" WHERE "ID" = $1', array($cid))['data'][0]['name']; $this->question = $q; $this->answers = array($a0, $a1, $a2, $a3); - print_r($this->answers); shuffle($this->answers); - print_r($this->answers); - $this->correct_answer_position = array_search($a0, $this->answers); - print_r($this->correct_answer_position); + $ca_position = array_search($a0, $this->answers); $this->category_id = $cid; $this->category = $c; + $db->query('UPDATE "Games" SET "current_right_answer" = $1 WHERE "ID" = $2', array($ca_position, $uid)); } public static function get_next_question($db, $uid) { $qid = $db->query('SELECT "Questions_ID" FROM "GamesQuestions" WHERE "Games_ID" = $1 LIMIT 1', array($uid)) ['data'][0]['Questions_ID']; - $question = new Question($db, $qid); + $question = new Question($db, $uid, $qid); $db->query('DELETE FROM "GamesQuestions" WHERE "Games_ID" = $1 AND "Questions_ID" = $2', array($uid, $qid)); $question_object = $question->get_question_object(); return $question_object;