view php/read/getLeaderboard.php @ 35:86f79bc1d142

refactor to split out shareable fn to actually do an Amazon API request
author Charlie Root
date Fri, 04 Jan 2019 12:54:12 -0500
parents 077b0a0a3e6d
children 385ddd7c4b55 b7376319d25a
line wrap: on
line source

<?PHP

include "../../../private/db.php";

$query = "CALL b_getLeaderboard()";
$results = mysqli_query($link, $query) or exit( mysqli_error( $link ));

$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);


?>