-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpagination.php
executable file
·116 lines (105 loc) · 4.73 KB
/
pagination.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
<?php
$limit = $settings['pagination'];
$targetpage = "index.php";
$prependP = (isset($_GET['page'])) ? "" : $prepend;
$query = "SELECT COUNT(*) as num FROM `servers` WHERE `disabled` = 0 {$offline_filter} {$game_filter} {$country_filter} {$map_filter}";
$total_pages = $database->query($query)->fetch_assoc();
$total_pages = $total_pages['num'];
$stages = 3;
if (!isset($_GET['page'])) { $_GET['page'] = 0;} else {$page = $_GET['page'];}
$page = $database->escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
// Get page data
$query1 = "SELECT * FROM `servers` LIMIT $limit";
$result = $database->query($query1);
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
echo "<div class='pagination'>";
$paginate = '';
// if($lastpage > 1)
// {
echo "<ul>";
// Previous
if ($page > 1){
echo "<li><a href='$targetpage?" . $prependP . "page=$prev'><</a></li>";
}
else{
echo "<li class='disabled'><a href='#'><</a></li>"; }
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
echo "<li class='active'><a href='#'>$counter</a></li>";
}else{
echo "<li><a href='$targetpage?" . $prependP . "page=$counter'>$counter</a></li>";}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
echo "<li class='active'><a href='#'>$counter</a></li>";
}else{
echo "<li><a href='$targetpage?" . $prependP . "page=$counter'>$counter</a></li>";}
}
echo "<li><a href='#'>...</a></li>";
echo "<li><a href='$targetpage?" . $prependP . "page=$LastPagem1'>$LastPagem1</a></li>";
echo "<li><a href='$targetpage?" . $prependP . "page=$lastpage'>$lastpage</a></li>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
echo "<li><a href='$targetpage?" . $prependP . "page=1'>1</a></li>";
echo "<li><a href='$targetpage?" . $prependP . "page=2'>2</a></li>";
echo "<li><a href='#'>...</a><li>";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
echo "<li class='active'><a href='#'>$counter</a></li>";
}else{
echo "<li><a href='$targetpage?" . $prependP . "page=$counter'>$counter</a></li>";}
}
echo "...";
echo "<li><a href='$targetpage?" . $prependP . "page=$LastPagem1'>$LastPagem1</a></li>";
echo "<li><a href='$targetpage?" . $prependP . "page=$lastpage'>$lastpage</a></li>";
}
// End only hide early pages
else
{
echo "<li><a class='button' href='$targetpage?" . $prependP . "page=1'>1</a></li>";
echo "<li><a class='button' href='$targetpage?" . $prependP . "page=2'>2</a><li>";
echo "<li><a href='#'>...</a></li>";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
echo "<li class='active'><a href='#'>$counter</a></li>";
}else{
echo "<li><a href='$targetpage?" . $prependP . "page=$counter'>$counter</a></li>";}
}
}
}
// Next
if ($page < $counter - 1){
echo "<li><a href='$targetpage?" . $prependP . "page=$next'>></a></li>";
}else{
echo "<li class='disabled'><a href='#'>></a></li>";
}
echo "</ul>";
// }
// Pagination
echo "</div>";
?>