summaryrefslogtreecommitdiffstats
path: root/includes/datas.php
blob: 912eea8e1937d17d780ef218188ab393c1655c6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?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 class='score'>";
		$output .= "<tr>";
		$output .= "<th>Rank</th>";
		$output .= "<th>Name</th>";
		$output .= "<th>Moves</th>";
		$output .= "<th>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: #356;'>";
			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;
}

?>