-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopscores.php
41 lines (37 loc) · 865 Bytes
/
topscores.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
<?php
$fullname = $_REQUEST['fullname'];
$wordcount = intval($_REQUEST['wordcount']);
if ($wordcount < 9) {
$wordcount = 9;
}
if ($wordcount > 15) {
$wordcount = 15;
}
$list = array();
if (($handle = fopen("datafile", "r")) !== FALSE) {
while (($data = fgetcsv($handle)) !== FALSE) {
$list[] = $data;
}
fclose($handle);
}
foreach ($list as $key => $item) {
$item = json_decode($item[0]);
if ($wordcount == $item->wordcount) {
$data[] = $item;
}
}
function data_sort($a, $b) {
if ($a->score >= $b->score) return -1;
return 1;
}
$top_score = '';
$high_score = '';
usort($data, 'data_sort');
$top_score = $data[0]->score;
foreach ($data as $key => $item) {
if ($item->fullname == $fullname) {
$high_score = $item->score;
break;
}
}
?>{"HS":"<?=$high_score?>", "TS":"<?=$top_score?>"}