forked from github/game-off-2012
-
Notifications
You must be signed in to change notification settings - Fork 129
/
score.php
56 lines (37 loc) · 1.43 KB
/
score.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
53
54
55
56
<?php
// SERVER SIDE SCRIPT USED TO SAVE SCORE AND RETURN RANKING
mysql_connect('localhost', 'USERNAME', 'PASSWORD');
mysql_select_db('hotfixscores');
if (isset($_REQUEST['score'])) {
$time = time();
$score = intval($_REQUEST['score']);
if ($score < 0) {
$score = 0;
}
mysql_query('INSERT INTO scores (score, created_at) VALUES ('.mysql_real_escape_string($score).', '.mysql_real_escape_string($time).');');
$rank_24 = 0;
$total_24 = 0;
$query = 'SELECT COUNT(id) as nb FROM scores WHERE score > '.mysql_real_escape_string($score).' AND created_at > '.mysql_real_escape_string($time - 24 * 3600).';';
$result = mysql_query($query);
while ($res = mysql_fetch_array($result)) {
$rank_24 = $res['nb'] + 1;
}
$query = 'SELECT COUNT(id) as nb FROM scores WHERE created_at > '.mysql_real_escape_string($time - 24 * 3600).';';
$result = mysql_query($query);
while ($res = mysql_fetch_array($result)) {
$total_24 = $res['nb'];
}
$rank_overall = 0;
$total_overall = 0;
$query = 'SELECT COUNT(id) as nb FROM scores WHERE score > '.mysql_real_escape_string($score).';';
$result = mysql_query($query);
while ($res = mysql_fetch_array($result)) {
$rank_overall = $res['nb'] + 1;
}
$query = 'SELECT COUNT(id) as nb FROM scores;';
$result = mysql_query($query);
while ($res = mysql_fetch_array($result)) {
$total_overall = $res['nb'];
}
echo $rank_24.' / '.$total_24.':'.$rank_overall.' / '.$total_overall;
}