效果图
1.测试实例test.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
|
<?php header( "Content-Type: text/html; charset=utf-8" ); date_default_timezone_set( "Asia/Shanghai" ); //时区 require_once ( 'page.class.php' ); $showrow = 5; $curpage = empty ( $_GET [ 'page' ]) ? 1 : $_GET [ 'page' ]; $url = "?page={page}" ; $dsn = 'mysql:host=xxx.xxx.80.xxx;dbname=admin' ; $pdo = new PDO( $dsn , 'root' , 'root' ); $pdo ->query( 'set names utf8' ); $sql = "SELECT * from operator_list where 1=1" ; $res_gg = $pdo ->query( "SELECT count(*) as ctn from operator_list where 1=1;" ); $result = $res_gg ->fetch(); $total = $result [ "ctn" ]; if (! empty ( $_GET [ 'page' ]) && $total != 0 && $curpage > ceil ( $total / $showrow )) { $curpage = ceil ( $total_rows / $showrow ); } $sql .= " LIMIT " . ( $curpage - 1) * $showrow . ",$showrow;" ; $res_zz = $pdo ->query( $sql ); $result = $res_zz ->fetchAll(); //print_r(json_encode($result));die; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" > <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <title></title> <meta name= "keywords" content= "入库" /> <meta name= "description" content= "入库" /> <script type= "text/javascript" src= "static/js/jquery-1.11.0.min.js?v=1" ></script> <link rel= "stylesheet" type= "text/css" href= "static/css/common.css" rel= "external nofollow" /> </head> <body> <div class = "head" > <!-- <div class = "head_inner clearfix" >--> <!-- <ul id= "nav" >--> <!-- <li><a href= "javascript;" rel= "external nofollow" rel= "external nofollow" >商品列表</a></li>--> <!-- <li><a href= "javascript;" rel= "external nofollow" rel= "external nofollow" >详情列表</a></li>--> <!-- </ul>--> <!-- <a class = "logo" href= "javascript" rel= "external nofollow" > <img src= "javascript;" alt= "公司logo" /></a> --> <!-- </div>--> </div> <div class = "container" > <div class = "demo" > <h2 class = "title" >报表</h2> <div class = "showData" > <table width= "100%" border= "0" align= "center" style= "border:1px solid #ccc;" cellpadding= "0" cellspacing= "1" > <tr align= "center" > <td>ID</td> <td>商品编号</td> <td>订阅状态</td> <td>商品状态</td> <td>修改时间</td> <td>创建时间</td> </tr> <?php if (! empty ( $result )) { foreach ( $result as $k => $v ) { ?> <tr align= "center" > <td><?php echo $v [ 'id' ]; ?></td> <td><?php echo $v [ "customer_id" ]; ?></td> <td><?php echo $v [ "name" ]; ?></td> <td><?php echo $v [ "role_id" ]; ?></td> <td><?php echo $v [ "status" ]; ?></td> <td><?php echo $v [ "cdate" ]; ?></td> </tr> <?php } } ?> </table> </div> <div class = "showPage" > <?php if ( $total > $showrow ) { //总记录数大于每页显示数,显示分页 $page = new page( $total , $showrow , $curpage , $url , 3); echo $page ->myde_write(); } ?> </div> </div> </div> <div class = "foot" > 阿里巴巴:<a href= "#" rel= "external nofollow" target= "_blank" >https: //www.taobao.com</a> </div> </body> </html> |
2.封装的page分页类page.class.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
<?php /* * ********************************************* * @类名: page * @参数: $myde_total - 总记录数 * $myde_size - 一页显示的记录数 * $myde_page - 当前页 * $myde_url - 获取当前的url * @功能: 分页实现 */ class page { private $myde_total ; //总记录数 private $myde_size ; //一页显示的记录数 private $myde_page ; //当前页 private $myde_page_count ; //总页数 private $myde_i ; //起头页数 private $myde_en ; //结尾页数 private $myde_url ; //获取当前的url /* * $show_pages * 页面显示的格式,显示链接的页数为2*$show_pages+1。 * 如$show_pages=2那么页面上显示就是[首页] [上页] 1 2 3 4 5 [下页] [尾页] */ private $show_pages ; public function __construct( $myde_total = 1, $myde_size = 1, $myde_page = 1, $myde_url , $show_pages = 2) { $this ->myde_total = $this ->numeric( $myde_total ); $this ->myde_size = $this ->numeric( $myde_size ); $this ->myde_page = $this ->numeric( $myde_page ); $this ->myde_page_count = ceil ( $this ->myde_total / $this ->myde_size); $this ->myde_url = $myde_url ; if ( $this ->myde_total < 0) $this ->myde_total = 0; if ( $this ->myde_page < 1) $this ->myde_page = 1; if ( $this ->myde_page_count < 1) $this ->myde_page_count = 1; if ( $this ->myde_page > $this ->myde_page_count) $this ->myde_page = $this ->myde_page_count; $this ->limit = ( $this ->myde_page - 1) * $this ->myde_size; $this ->myde_i = $this ->myde_page - $show_pages ; $this ->myde_en = $this ->myde_page + $show_pages ; if ( $this ->myde_i < 1) { $this ->myde_en = $this ->myde_en + (1 - $this ->myde_i); $this ->myde_i = 1; } if ( $this ->myde_en > $this ->myde_page_count) { $this ->myde_i = $this ->myde_i - ( $this ->myde_en - $this ->myde_page_count); $this ->myde_en = $this ->myde_page_count; } if ( $this ->myde_i < 1) $this ->myde_i = 1; } //检测是否为数字 private function numeric( $num ) { if ( strlen ( $num )) { if (!preg_match( "/^[0-9]+$/" , $num )) { $num = 1; } else { $num = substr ( $num , 0, 11); } } else { $num = 1; } return $num ; } //地址替换 private function page_replace( $page ) { return str_replace ( "{page}" , $page , $this ->myde_url); } //首页 private function myde_home() { if ( $this ->myde_page != 1) { return "<a href='" . $this ->page_replace(1) . "' id="codetool">
3.css样式
具体的大家可以多学习别人的php分页类然后多练就可以了。 原文链接:https://blog.csdn.net/u013101178/article/details/81904139 相关文章
热门资讯 |