This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaderboard.php
52 lines (50 loc) · 1.58 KB
/
leaderboard.php
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
/**
* 排行榜
* @param 'stunum':string
* @return [{},{},...]
* -1:no login
*/
require_once("function/db_mysqli.php");
$db=new DB();
if(!empty($_POST['stunum']))
{
$res_top_100=array();
$res_nearby=array();
$top_challenge = $db->getAll("select * from user_game where stunum order by challenge_best desc, challenge_time asc, challenge_first asc");
for($i = 0; $i < 100; $i++) {
$val = $top_challenge[$i];
array_push($res_top_100, array(
"rank" => $i+1,
"stunum" => $val['stunum'],
"challenge_best" => $val['challenge_best'],
"challenge_first" => date("Y-m-d H:i:s", $val['challenge_first']),
'challenge_time' => $val['challenge_time']
));
}
$myrank = -1;
foreach($top_challenge as $key => $val)
if($val['stunum'] == $_POST['stunum'])
$myrank = $key;
if($myrank == -1) $res_nearby = array(-1);
else {
for($i = max($myrank - 2, 0); $i < min($myrank + 3, count($top_challenge)); $i++) {
$val = $top_challenge[$i];
array_push($res_nearby,array(
"rank" => $i + 1,
"stunum" => $val['stunum'],
"challenge_best" => $val['challenge_best'],
"challenge_first" => date("Y-m-d H:i:s", $val['challenge_first']),
'challenge_time' => $val['challenge_time']
));
}
}
echo json_encode(array(
"top100"=>$res_top_100,
"nearby"=>$res_nearby,
));
}else echo json_encode(array(
"top100"=>array(-1),
"nearby"=>array(-1),
));
?>