rdgorodrigo

Untitled

Oct 27th, 2020
780
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     //Retrieve our score along with leaderboard
  3.     if(isset($_POST["email"]) && isset($_POST["username"])){
  4.         $returnData = array();
  5.        
  6.         $email = $_POST["email"];
  7.         $username = $_POST["username"];
  8.  
  9.         //Connect to database
  10.         require dirname(__FILE__) . '/database.php';
  11.        
  12.         //Get our score and rank
  13.         $returnData[] = "User";
  14.         if ($stmt = $mysqli_conection->prepare("SELECT us.user_score,
  15.             (SELECT COUNT(row_id) FROM sc_user_scores WHERE user_score >= us.user_score LIMIT 1) as rank
  16.             FROM sc_user_scores us
  17.             WHERE us.user_id = (SELECT user_id FROM sc_users WHERE email = ? AND username = ? LIMIT 1) LIMIT 1")) {
  18.            
  19.             /* bind parameters for markers */
  20.             $stmt->bind_param('ss', $email, $username);
  21.                
  22.             /* execute query */
  23.             if($stmt->execute()){
  24.                
  25.                 /* store result */
  26.                 $stmt->store_result();
  27.  
  28.                 if($stmt->num_rows > 0){
  29.                
  30.                     /* bind result variables */
  31.                     $stmt->bind_result($score_tmp, $user_rank);
  32.  
  33.                     /* fetch value */
  34.                     $stmt->fetch();
  35.                    
  36.                     //Append
  37.                     $returnData[0] .= "," . $score_tmp . "," . $user_rank;
  38.  
  39.                 }
  40.                
  41.                 /* close statement */
  42.                 $stmt->close();
  43.                
  44.             }
  45.         }
  46.        
  47.         //Get top 100 players
  48.         if ($stmt = $mysqli_conection->prepare("SELECT u.username, us.user_score
  49.             FROM sc_users u RIGHT JOIN sc_user_scores us ON u.user_id = us.user_id
  50.             WHERE u.user_id IS NOT NULL ORDER BY us.user_score DESC LIMIT 100")) {
  51.                
  52.             /* execute query */
  53.             if($stmt->execute()){
  54.                
  55.                 $result = $stmt->get_result();
  56.  
  57.                 while ($row = $result->fetch_assoc())
  58.                 {
  59.                     $returnData[] = $row["username"] . "," . $row["user_score"];
  60.                 }
  61.                
  62.                 /* close statement */
  63.                 $stmt->close();
  64.                
  65.             }
  66.         }
  67.        
  68.         //The returned string will use '|' symbol for separation between player data and ',' for separation inside the player data
  69.         echo implode('|', $returnData);
  70.     }else{
  71.         echo "Missing data";
  72.     }
  73. ?>
RAW Paste Data