forked from arcxingye/EatKano
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rank.php
118 lines (115 loc) · 5.13 KB
/
rank.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html lang="zh">
<head>
<title>吃掉小鹿乃-排行榜</title>
<meta item="description" content="来看神仙" />
<meta charset="utf-8" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<?php
@require 'conn.php';
//最大显示页数
$max_pages = 9;
$lbtype = isset($_GET['lbtype']) ? $_GET['lbtype'] : 'day';
//每页显示数量
$num = 30;
$CurrentPage = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
$CurrentUser = $_GET['name'];
$offset = ($CurrentPage - 1) * $num;
if ($lbtype == 'day') {
$title = "日";
$cond = "to_days(time) = to_days(now())";
}
if ($lbtype == 'week') {
$title = "周";
$cond = "DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(time)";
}
if ($lbtype == 'month') {
$title = "月";
$cond = "DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(time)";
}
?>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="./">返回</a></li>
</ol>
</nav>
<div class="page-header text-center">
<h1>排行榜(<?php echo $title; ?>榜)</h1>
<a href="?lbtype=day<?php echo $CurrentUser ? "&name=" . $CurrentUser : "" ?>"><button type="button" class="btn btn-outline-secondary btn-sm">日榜</button></a>
<a href="?lbtype=week<?php echo $CurrentUser ? "&name=" . $CurrentUser : "" ?>"><button type="button" class="btn btn-outline-secondary btn-sm">周榜</button></a>
<a href="?lbtype=month<?php echo $CurrentUser ? "&name=" . $CurrentUser : "" ?>"><button type="button" class="btn btn-outline-secondary btn-sm">月榜</button></a>
<br/>tips:大家不要作弊哦~ฅ'ω'ฅ♪
</div>
<div class="list-group">
<?php
$rank = $offset;
$filtercond = " ORDER BY score DESC limit ?,?;";
$data_sql = "SELECT * FROM " . $ranking . " where " . $cond . $filtercond;
if ($data_stmt = $link->prepare($data_sql)) {
$data_stmt->bind_param("ii", $offset, $num);
$data_stmt->execute();
$data_stmt->store_result();
$data_stmt->bind_result($id, $score, $name, $time, $system, $area, $message, $attempts);
while ($data_stmt->fetch()) {
$rank += 1;
echo "<a href='#' class='list-group-item list-group-item-action'><div class='d-flex w-100 justify-content-between'>
<h5 class='mb-1'>" . $rank . "位 " . $name . "</h5><small>" . $time . "</small></div>
<p class='mb-1'>SCORE: " . $score . " TRY: " . $attempts . " -" . $system . " -" . $area . "</p>
<small>" . ($message ? $message : "这个人很懒什么也没留下") . "</small></a>";
}
$data_stmt->close();
}
?>
<nav aria-label="Page navigation example" style="margin-bottom:3em;">
<ul class="pagination">
<?php
$rows_sql = "SELECT count(*) FROM " . $ranking . " where " . $cond;
$rows_data = mysqli_query($link, $rows_sql);
$rows = mysqli_fetch_row($rows_data)[0];
$rows = $rows > $num * $max_pages ? $num * $max_pages : $rows;
$total = ceil($rows / $num);
if ($total > 1) {
if ($CurrentPage > 1) {
echo "<li class='page-item'><a class='page-link' href='?lbtype=" . $lbtype . "&page=" . ($CurrentPage - 1) . ($CurrentUser ? "&name=" . $CurrentUser : "") . "' aria-label='Previous'><span aria-hidden='true'>«</span></a></li>";
}
for ($p = 1; $p <= $total; $p++) {
echo "<li class='page-item " . ($CurrentPage == $p ? "active" : "") . "'><a class='page-link' href='?lbtype=" . $lbtype . "&page=" . $p . ($CurrentUser ? "&name=" . $CurrentUser : "") . "'>" . $p . "</a></li>";
}
if ($total > $CurrentPage) {
echo "<li class='page-item'><a class='page-link' href='?lbtype=" . $lbtype . "&page=" . ($CurrentPage + 1) . ($CurrentUser ? "&name=" . $CurrentUser : "") . "' aria-label='Next'><span aria-hidden='true'>»</span></a></li>";
}
}
?>
</ul>
</nav>
</div>
<footer class='fixed-bottom container'>
<div class='row shadow bg-info rounded'>
<div style='padding:0.2em 1em;'>
<?php
if ($CurrentUser) {
//查询当前名字历史记录
$score_sql = "SELECT score,time,attempts FROM " . $ranking . " where name=?";
$score_stmt = $link->prepare($score_sql);
$score_stmt->bind_param("s", $CurrentUser);
$score_stmt->bind_result($score, $time, $attempts);
$score_stmt->execute();
if ($score_stmt->fetch()) {
echo $CurrentUser . " 的最高记录 已上传" . $attempts . "次<br/>" . "SCORE:" . $score . " " . $time;
} else {
echo "没有找到 " . $CurrentUser . " 的记录(或被过滤)";
}
$score_stmt->close();
} else {
echo "小提示:你玩前还没有填名字";
}
$link->close();
?>
</div>
</div>
</footer>
</body>
</html>