T201704051123
This commit is contained in:
@@ -32,7 +32,8 @@ class Question
|
||||
$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));
|
||||
$db->query('UPDATE "Games" SET "current_right_answer" = $1, "current_category" = $2 WHERE "ID" = $3',
|
||||
array($ca_position, $cid, $uid));
|
||||
}
|
||||
|
||||
public static function get_next_question($db, $uid) {
|
||||
|
||||
19
answer.php
19
answer.php
@@ -37,6 +37,7 @@ if($uid == '') {
|
||||
['data'][0]['exists'] == 'f') {
|
||||
$error = 13104;
|
||||
} else {
|
||||
//set time and points
|
||||
$old_points = $db->query('SELECT "current_score" FROM "Games" WHERE "ID" = $1', array($uid))
|
||||
['data'][0]['current_score'];
|
||||
$new_points = $old_points + $score;
|
||||
@@ -46,6 +47,24 @@ if($uid == '') {
|
||||
['data'][0]['total_time'];
|
||||
$new_time = $old_time + $time;
|
||||
$db->query('UPDATE "Games" SET "total_time" = $1 WHERE "ID" = $2', array($new_time, $uid));
|
||||
|
||||
//set high score
|
||||
if($db->query('SELECT EXISTS (SELECT 1 FROM "Highscores" WHERE "Users_ID" = $1 AND "Categories_ID" = $2)',
|
||||
array($uid, $cid))['data'][0]['exists'] == 'f') {
|
||||
$db->query('INSERT INTO "Highscores" ("Users_ID", "Categories_ID"), VALUES ($1, $2)', array($uid, $cid));
|
||||
}
|
||||
$old_hi_data = $db->query('SELECT "score", "answered_questions" FROM "Highscores" WHERE "Users_ID" = $1
|
||||
AND "Categories_ID" = $2', array($uid, $cid))['data'][0];
|
||||
$old_hi_score_pq = $old_hi_data['score'];
|
||||
$old_hi_questions = $old_hi_data['answered_questions'];
|
||||
$old_hi_score_total = $old_hi_score_pq * $old_hi_questions;
|
||||
$new_hi_score_total = $old_hi_score_total + $score;
|
||||
$new_hi_questions = $old_hi_questions++;
|
||||
$new_hi_score_pq = intval($new_hi_score_total / $new_hi_questions);
|
||||
$db->query('UPDATE "Highscores" SET "score" = $1, "answered_questions" = $2',
|
||||
array($new_hi_score_pq, $new_hi_questions));
|
||||
|
||||
//create next question if existing, end object otherwise
|
||||
if($db->query('SELECT EXISTS (SELECT 1 FROM "GamesQuestions" WHERE "Games_ID" = $1)',array($uid))
|
||||
['data'][0]['exists'] == 't') {
|
||||
$next_question = Question::get_next_question($db, $uid);
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
* Time: 10:18
|
||||
*/
|
||||
|
||||
require_once('includes.inc.php');
|
||||
$data = '';
|
||||
$error = 0;
|
||||
$uid = isset($_GET['uid']) ? $_GET['uid'] : '';
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user