OSDN Git Service

[modify]死因の文字列をPHP側でなくSQL文で作成する
[hengband/web.git] / popularity_ranking.php
1 <?php
2 //ini_set('display_errors', 'On');
3
4 ini_set('log_errors', 'On');
5 ini_set('error_log', 'errors/'.pathinfo(__FILE__, PATHINFO_FILENAME).'.log');
6
7 ini_set('zlib.output_compression', 'On');
8
9 include "db_common.inc";
10
11 function print_popularity_table($stat, $id_name, $name, $current_sort_key)
12 {
13     echo <<<EOM
14 <table>
15 <tr>
16 <th>#</th>
17 <th>$name</th>
18 EOM;
19     
20     foreach ([
21         '計' => 'total_count',
22         '男性' => 'male_count',
23         '女性' => 'female_count',
24         '勝利' => 'winner_count',
25         '平均スコア' => 'average_score',
26         '最大スコア' => 'max_score',
27     ] as $name => $sort_key) {
28         if ($sort_key !== $current_sort_key)
29             echo "<th><a href='popularity_ranking.php?sort_key=${sort_key}'>${name}</a></th>";
30         else {
31             echo "<th><strong>${name}</strong></th>";
32         }
33     }
34     echo "</tr>\n";
35
36     $rank = 0;
37     foreach ($stat as $k => $s) {
38         $rank ++;
39         $name_link = "<a href='score_ranking.php?{$id_name}={$s['id']}'>{$s['name']}</a></td>";
40         $average_score = floor($s['average_score']);
41         echo <<<EOM
42 <tr>
43 <td>$rank</td>
44 <td>$name_link</td>
45 <td>{$s['total_count']}</td>
46 <td>{$s['male_count']}</td>
47 <td>{$s['female_count']}</td>
48 <td>{$s['winner_count']}</td>
49 <td>$average_score</td>
50 <td>{$s['max_score']}</td>
51 </tr>
52 EOM;
53     }
54
55     echo "</table>";
56 }
57
58
59 $db = new ScoreDB();
60
61 $time_start = microtime(true);
62
63 $sort_key_column = filter_input(INPUT_GET, 'sort_key') ?: 'total_count';
64 $statistics = $db->get_statistics_tables($sort_key_column);
65
66 $query_time = microtime(true) - $time_start;
67 ?>
68
69 <!DOCTYPE html>
70 <html>
71 <head>
72 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
73 <meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
74 <title>変愚蛮怒 人気のある種族・職業・性格</title>
75 </head>
76
77 <small>
78 <?php
79 echo sprintf("(%.2f 秒)", $query_time);
80 ?>
81 </small>
82 <hr>
83 <h1>人気のある種族</h1>
84
85 <?php
86 print_popularity_table($statistics['race'], 'race_id', "種族", $sort_key_column);
87 ?>
88
89 <hr>
90 <h1>人気のある職業</h1>
91
92 <?php
93 print_popularity_table($statistics['class'], 'class_id', "職業", $sort_key_column);
94 ?>
95
96 <hr>
97 <h1>人気のある性格</h1>
98
99 <?php
100 print_popularity_table($statistics['personality'], 'personality_id', "性格", $sort_key_column);
101 ?>