-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpagination.php
More file actions
91 lines (68 loc) · 1.85 KB
/
Copy pathpagination.php
File metadata and controls
91 lines (68 loc) · 1.85 KB
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
<?php
require 'connection.php';
date_default_timezone_set("America/Vancouver");
$count_sql = 'select * from user';
$result_1 = mysqli_query($conn, $count_sql);
$count = mysqli_affected_rows($conn);
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$num = 2;
$total= ceil($count / $num);
if ($page <= 1) {
$page = 1;
}
if ($page >= $total) {
$page = $total;
}
$start = $page - 2;
if($page <= 4){
$start = 1;
}
if($page >= $total-3){
$start = $total-6;
}
if($total < 7){
$start = 1;
}
$page_next = $page+1;
$offset = ($page-1) * $num;
$sql = "select * from user order by time desc limit $offset,$num";
$result_2 = mysqli_query($conn, $sql);
$All = mysqli_fetch_all($result_2, MYSQLI_ASSOC);
// var_dump($All);
if ($result_2 and mysqli_num_rows($result_2)) {
}else{
echo 'no data';
echo mysqli_error($conn);
}
//The function of showing the pagination bottons.
function pagination(){
global $total,$start,$page,$page_next;
if($total >= 7){
for($i=$start;$i<=($start+7);$i++){
if($page == $i){
echo "<span>$i</span>";
}elseif($i ==($start+6) and ($i-1) != ($total-1)){
echo "<span>...</span>";
}elseif($i ==($start+6) and ($i-1) == ($total-1)){
continue;
}elseif($i ==($start+7) and $page != $total){
echo "<a href='?page=$total'>$total</a>";
}elseif($i ==($start+7) and $page == $total){
continue;
}else{
echo "<a href='?page=$i'>$i</a>";
}
}
}else{
for($i=$start;$i<=$total;$i++){
if($page == $i){
echo "<span>$i</span>";
}else{
echo "<a href='?page=$i'>$i</a>";
}
}
}
echo "<a href='?page=$page_next'>Next</a>";
}
mysqli_close($conn);
?>