Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Retrieve our score along with leaderboard
- if(isset($_POST["email"]) && isset($_POST["username"])){
- $returnData = array();
- $email = $_POST["email"];
- $username = $_POST["username"];
- //Connect to database
- require dirname(__FILE__) . '/database.php';
- //Get our score and rank
- $returnData[] = "User";
- if ($stmt = $mysqli_conection->prepare("SELECT us.user_score,
- (SELECT COUNT(row_id) FROM sc_user_scores WHERE user_score >= us.user_score LIMIT 1) as rank
- FROM sc_user_scores us
- WHERE us.user_id = (SELECT user_id FROM sc_users WHERE email = ? AND username = ? LIMIT 1) LIMIT 1")) {
- /* bind parameters for markers */
- $stmt->bind_param('ss', $email, $username);
- /* execute query */
- if($stmt->execute()){
- /* store result */
- $stmt->store_result();
- if($stmt->num_rows > 0){
- /* bind result variables */
- $stmt->bind_result($score_tmp, $user_rank);
- /* fetch value */
- $stmt->fetch();
- //Append
- $returnData[0] .= "," . $score_tmp . "," . $user_rank;
- }
- /* close statement */
- $stmt->close();
- }
- }
- //Get top 100 players
- if ($stmt = $mysqli_conection->prepare("SELECT u.username, us.user_score
- FROM sc_users u RIGHT JOIN sc_user_scores us ON u.user_id = us.user_id
- WHERE u.user_id IS NOT NULL ORDER BY us.user_score DESC LIMIT 100")) {
- /* execute query */
- if($stmt->execute()){
- $result = $stmt->get_result();
- while ($row = $result->fetch_assoc())
- {
- $returnData[] = $row["username"] . "," . $row["user_score"];
- }
- /* close statement */
- $stmt->close();
- }
- }
- //The returned string will use '|' symbol for separation between player data and ',' for separation inside the player data
- echo implode('|', $returnData);
- }else{
- echo "Missing data";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement