summaryrefslogtreecommitdiffstats
path: root/includes/datas.php
blob: 0d3d0c5ca2f055d26060476ebd677f3a2bb1e63e (plain)
1
<?PHP
// For interaction with the SQL database.
//

include_once('db.inc.php');

//Select Stats/Scores.
function topScores($mapid, $top = 5) {
	$sql = "
	SELECT 
		timediff(solutions.dateModified, TIMESTAMP(CURDATE())) as diff,
		users.displayName as display,
		solutions.moves as m,
		users.ID as ID
	FROM 
		`users`
		JOIN `solutions`
			ON users.ID = solutions.userID
	WHERE solutions.mapID = '$mapid'
	ORDER BY solutions.moves DESC, solutions.dateModified ASC
	LIMIT $top
	";
	$result = mysql_query($sql);

	if (mysql_num_rows($result) > 0) {
		$output .= "<table style='border:1px solid #FFF'>";
		$output .= "<tr>";
		$output .= "<th style='border:1px solid #ccc'>Rank</th>";
		$output .= "<th style='border:1px solid #ccc'>Name</th>";
		$output .= "<th style='border:1px solid #ccc'>Moves</th>";
		$output .= "<th style='border:1px solid #ccc'>Time taken</th>";
		$output .= "</tr>";
		while (list($diff, $display, $moves, $userID) = mysql_fetch_row($result)) {
			$i++;
			if ($_SESSION['userID'] == $userID)
				$output .= "<tr style='background-color: #338899;'>";
			else
				$output .= "<tr>";
			
			$output .= "<td>$i</td>";
			$output .= "<td><span title='UserID: $userID'>$display</span></td>";
			$output .= "<td>$moves</td>";
			$output .= "<td>$diff</td>";
			//$output .= "<b>$i. <span title='UserID: $userID'>$display</span> with $moves moves. In $diff<br /></b>";
			$output .= "</tr>";
		}
		$output .= "</table>";
	}
	return $output;
}





?>