T201704051123
This commit is contained in:
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);
|
||||
|
||||
Reference in New Issue
Block a user