// gets the lowest score in the ranking table $btm = end($results); // sets $beaten so that we know if we beat the last person in the ranking $score >= $btm ? $beaten = true : ($beaten = false); //print_r($results); if (isset($_SESSION['username'])) { $username = $_SESSION['username']; $logged = true; if ($score != 0 && $score >= $btm) { $id = User::insert_new_score($score, $username, $time, $perc, $_SESSION['odp_poprawne'], $_SESSION['hashed_email']); User::update_user_stats($username); } } if ($beaten) { // selects top 30 scores (default) $r = User::find_top_scores(50); // finds the position based on the points player scored $key = array_search($score, $r); // echo $key; } // checks if player's score is greater than bottom score from the table $beaten ? $color = "high" : ($color = "low"); // odmiana sekund i minut $r = s2m($time); //print_r($r); $czas = $r['min'] != 0 ? ileMinut($r['min']) : false; $czas .= " " . ileSekund($r['sec']); ?> <div id="endWrap" class="oknoGry"> <div id="yourResult" class="resultsBlock roundCorners"> <?php
<?php require_once "initialize.php"; $ja['id'] = "none"; if ($_POST) { // zapisuje wynik $score = $_SESSION['zdobyte_punkty']; // if user is logged if (isset($_SESSION['username'])) { $name = $_SESSION['username']; $hashed_email = $_SESSION['hashed_email']; } else { $email = trim($db->escape_value($_POST['email'])); $name = trim($db->escape_value($_POST['name'])); $hashed_email = md5($email); } $time = $_SESSION['question_start_time'] - $_SESSION['game_start_time']; // percentage of correct answers $perc = round($_SESSION['odp_poprawne'] * 100 / $_SESSION['ilosc_odp']); // returned value is id of inserted row $ja['id'] = User::insert_new_score($score, $name, $time, $perc, $_SESSION['odp_poprawne'], $hashed_email); // selects top 30 scores (default) $r = User::find_top_scores(); // finds the position based on the points player scored (adding one cause of the zero based system) $ja['key'] = $key = array_search($score, $r) + 1; } echo json_encode($ja);