query('SELECT "question", "answer0", "answer1", "answer2", "answer3", "Categories_ID" FROM "Questions" WHERE "ID" = $1', array($id)); $q = $question_details[0]; $a0 = $question_details[1]; $a1 = $question_details[2]; $a2 = $question_details[3]; $a3 = $question_details[4]; $cid = $question_details[5]; $c = $db->query('SELECT "name" FROM "Categories" WHERE "ID" = $1', array($cid)); $this->question = $q; $this->answers = array('a0' => $a0, 'a1' => $a1, 'a2' => $a2, 'a3' => $a3); shuffle($this->answers); $this->correct_answer_position = array_search('a0', $this->answers); $this->category_id = $cid; $this->category = $c; } 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]['ID']; $question = new Question($db, $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; } // Create the question message for API. function get_question_object() { $question_object = array( 'categoryID' => $this->category_id, 'categoryName' => $this->category, 'question' => $this->question, 'answers' => [$this->answers['a0'], $this->answers['a1'], $this->answers['a2'], $this->answers['a3']] ); return $question_object; } }