-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagination.php
61 lines (58 loc) · 1.26 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
<?php
class Pagination{
var $sql;
var $page_string;
var $page_size;
function __construct($sql,$size){
$this->sql = $sql;
$this->page_size = $size;
}
function search(){
if(isset($_GET['page'])) //判断是否存在page参数,获得页面值,否则取1
{
$page = intval($_GET['page']);
}
else
{
$page = 1;
}
$result = mysql_query($this->sql);
$row = mysql_fetch_array($result);
//计算总页数
$amount = $row['amount'];
if($amount)
{
if($amount < $this->page_size){$page_count = 1;}
if($amount % $this->page_size){$page_count = (int)($amount / $this->page_size) + 1; }
else{$page_count = $amount / $this->page_size;}
}
else
{
$page_count = 1;
}
//翻页链接
$this->page_string = "";
if($page == 1)
{
$this->page_string .= "首页 | 上一页";
}
else
{
$this->page_string .= "<a href='?page=1'>首页</a> | <a href='?page=".($page-1)."'>上一页</a>";
}
$this->page_string .= "| $page/$page_count |";
if($page == $page_count)
{
$this->page_string .= "下一页 | 尾页";
}
else
{
$this->page_string .= "<a href='?page=".($page+1)."'>下一页</a> | <a href='?page=$page_count'>尾页</a>";
}
}
function print_pagination(){
$this->search();
echo $this->page_string;
}
}
?>