view php/read/getLeaderboard.php @ 53:dd93cb4b77ad

more debugging (too much for production), fallback to DB if getBookDetails is knocked back by Amazon
author Charlie Root
date Thu, 06 Jun 2019 16:37:20 -0400
parents a67bf725e87b
children
line wrap: on
line source

<?PHP

include "db.php";

$query = "CALL b_getLeaderboard()";
$results = my_query( $query,'gl');

$output = "";
$output .=  "<?xml version=\"1.0\"?>";
$output .=  "<Leaderboard>";

$leaderCount = 0;

while($line = mysqli_fetch_assoc($results)) {
	if($leaderCount < 10)
	{
		
		
		$id = trim($line["UserID"]);
		
		if($id != 42)
		{
			$name = trim($line["DisplayName"]);
			$score = trim($line["Score"]);
			
			if($name == "")
			{
				$name = "User" . $id;
			}
			
			$output .=  "<User>";
			$output .=  "<UserID>" . htmlspecialchars($id) . "</UserID>";
			$output .=  "<DisplayName>" . htmlspecialchars($name) . "</DisplayName>";
			$output .=  "<Score>" . htmlspecialchars($score) . "</Score>";
			$output .=  "</User>";
			$leaderCount++;
		}
	}
}

$output .=  "</Leaderboard>";

echo $output;

mysqli_close($link);


?>