本文实例讲述了PHP封装的page分页类定义与用法。分享给大家供大家参考,具体如下:

亲测有效,见下图=========>

1. 测试实例test.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;

?>

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

报表

style="border:1px solid #ccc;" cellpadding="0" cellspacing="1">

ID商品编号订阅状态商品状态修改时间创建时间

if (!empty($result)) {

foreach ($result as $k => $v) {

?>

<?php echo $v['id']; ?><?php echo $v["customer_id"]; ?><?php echo $v["name"]; ?><?php echo $v["role_id"]; ?><?php echo $v["status"]; ?><?php echo $v["cdate"]; ?>

}

}

?>

if ($total > $showrow) {//总记录数大于每页显示数,显示分页

$page = new page($total, $showrow, $curpage, $url, 3);

echo $page->myde_write();

}

?>

阿里巴巴:https://www.taobao.com

2. 封装的page分页类page.class.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 "首页";

} else {

return "

首页

";

}

}

//上一页

private function myde_prev() {

if ($this->myde_page != 1) {

return "上一页";

} else {

return "

上一页

";

}

}

//下一页

private function myde_next() {

if ($this->myde_page != $this->myde_page_count) {

return "下一页";

} else {

return"

下一页

";

}

}

//尾页

private function myde_last() {

if ($this->myde_page != $this->myde_page_count) {

return "尾页";

} else {

return "

尾页

";

}

}

//输出

public function myde_write($id = 'page') {

$str = "

";

$str.=$this->myde_home();

$str.=$this->myde_prev();

if ($this->myde_i > 1) {

$str.="

...

";

}

for ($i = $this->myde_i; $i <= $this->myde_en; $i++) {

if ($i == $this->myde_page) {

$str.="$i";

} else {

$str.="$i";

}

}

if ($this->myde_en < $this->myde_page_count) {

$str.="

...

";

}

$str.=$this->myde_next();

$str.=$this->myde_last();

$str.="

" . $this->myde_page_count .

"页" . $this->myde_total . "条数据

";

$str.="

";

return $str;

}

}

?>

3. css样式

html, body, div, span, h1, h2, h3, h4, h5, h6, p, pre,

a, code, em, img, small, strong, sub, sup, u, i, center,

dl, dt, dd, ol, ul, li, fieldset, form, label {

margin: 0;

padding: 0;

border: 0;

outline: 0;

font-size: 100%;

vertical-align: baseline;

background: transparent

}

a {

color: #007bc4;

text-decoration: none;

cursor: pointer;

}

.table_parameters a:hover {

text-decoration: none

}

a:hover {

text-decoration: underline

}

ol, ul {

list-style: none

}

table {

border-collapse: collapse;

border-spacing: 0

}

/*html {*/

/*background: url(../images/demo_bg.png)*/

/*}*/

body {

height: 100%;

font: 12px/18px "Microsoft Yahei", Tahoma, Helvetica,

Arial, Verdana, "\5b8b\4f53", sans-serif;

color: #51555c

}

img {

border: 0;

cursor: pointer;

}

.clearfix:after {

visibility: hidden;

display: block;

font-size: 0;

content: " ";

clear: both;

height: 0

}

.head {

/*border-bottom: 1px solid #dadada;*/

padding: 0 0 5px

}

.head_inner {

margin: 0 auto;

width: 980px

}

.container {

width: 80%;

/*min-height: 600px;*/

margin: 30px auto 0 auto;

border: 1px solid #d3d3d3;

background: #fff;

-moz-border-radius: 5px;

-khtml-border-radius: 5px;

-webkit-border-radius: 5px;

border-radius: 5px

}

.demo > h2.title {

margin: 4px 0 30px;

padding: 15px 0 10px 20px;

border-bottom: 1px solid #d3d3d3;

font-size: 18px;

color: #a84c10;

background: url(../images/arrow.jpg) no-repeat 2px 14px

}

.foot {

height: 60px;

padding: 10px 2px;

line-height: 24px;

text-align: center

}

.foot a:hover {

color: #51555c

}

.btn {

-webkit-border-radius: 3px;

-moz-border-radius: 3px;

-ms-border-radius: 3px;

-o-border-radius: 3px;

border-radius: 3px;

background-color: #ff8400;

color: #fff;

display: inline-block;

height: 28px;

line-height: 28px;

text-align: center;

padding: 0 12px;

transition: background-color .2s linear 0s;

border: 0;

cursor: pointer

}

.btn:hover {

background-color: #e95a00;

text-decoration: none

}

.demo {

width: 700px;

margin: 0 auto

}

ul.ul_demo li {

background: url("../images/demo_icon.gif") no-repeat scroll 0 6px;

line-height: 28px;

padding-left: 20px

}

.input, .table input[type='text'] {

border: 1px solid #ccc;

padding: 0 5px;

width: 220px;

height: 26px;

line-height: 26px

}

#nav {

float: right;

margin: 30px 0 0

}

#nav li {

float: left;

font-size: 16px;

margin-right: 20px

}

.btn.loading {

opacity: .5

}

h3 a.cur {

color: #f30;

}

.demo h3 a {

font-size: 14px;

margin: 0 10px 5px 0;

display: inline-block

}

.red {

color: red

}

.notice {

font-size: 14px;

margin-bottom: 10px;

}

.table_parameters {

border-left: 1px solid #d3d3d3;

border-top: 1px solid #d3d3d3;

margin: 6px auto;

font-size: 14px

}

.table_parameters tr.tr_head {

background: none repeat scroll 0 0 #f7f7f7;

font-weight: bold;

padding: 6px;

text-align: center

}

.table_parameters td, .table_parameters th {

border-bottom: 1px solid #d3d3d3;

border-right: 1px solid #d3d3d3;

line-height: 26px;

padding: 2px

}

h1 {

font: 32px "Microsoft Yahei";

margin: 40px auto;

text-align: center;

}

h2 {

font-size: 16px;

margin: 10px 0;

}

.menu {

height: 30px;

margin-bottom: 30px;

padding: 10px;

background-color: #f0f0f0;

text-align: center;

}

.menu a {

display: inline-block;

height: 30px;

padding: 0 20px;

line-height: 30px;

font-size: 14px;

color: #333;

text-decoration: none;

}

.menu a:hover {

color: #000;

background-color: #e9e9e9;

}

.menu .cur {

background-color: #ddd !important;

color: #000;

}

.vad a {

display: inline-block;

height: 36px;

line-height: 36px;

margin: 0 5px;

padding: 0 50px;

font-size: 14px;

text-align: center;

color: #eee;

text-decoration: none;

background-color: #222;

}

.vad a:hover {

color: #fff;

background-color: #000;

}

.thead {

width: 728px;

height: 90px;

margin: 0 auto;

}

textarea {

border: 1px solid #ccc;

font-size: 12px;

height: 100px;

line-height: 18px;

padding: 5px;

width: 300px;

}

.table td {

padding: 10px 0

}

.disabled {

opacity: .6;

filter: alpha(opacity=60)

}

.demo > p {

line-height: 30px;

font-size: 14px

}

.demo > p a {

font-size: 14px

}

.demo h3 {

font-size: 16px;

margin: 20px 0

}

select {

background-color: #fff;

background-position: right center;

background-repeat: no-repeat;

border: 1px solid #888;

border-radius: 3px;

box-sizing: border-box;

font: 12px/1.5 Tahoma, Arial, sans-serif;

height: 30px;

padding: 0 4px;

}

fieldset {

border: 1px solid #ccc;

border-radius: 5px;

margin: 1em 0;

padding: 10px 20px;

}

dl.row dt {

width: 2em;

}

dl.row dt {

clear: left;

float: left;

line-height: 30px;

padding: 5px;

text-align: right;

width: 6em;

}

dl.row dd {

float: left;

padding: 5px;

}

.pager {

text-align: right;

}

.pager a {

padding: 3px 8px;

margin-left: 3px;

line-height: 20px;

background: #f9f9f9;

border: 1px solid #DBDBDB;

text-decoration: none

}

.pager a:hover,

.pager a.current {

background-color: #7CD5B1;

color: #fff;

border: 1px solid #7CD5B1;

cursor: pointer;

}

.page {

text-align: center;

margin: 50px 0

}

.page a, .page span.prev_disabled {

border: 1px solid #ededed;

color: #3d3d3d;

font-weight: 700;

height: 35px;

line-height: 35px;

margin-left: 5px;

min-width: 9px;

padding: 0 13px;

text-align: center;

text-decoration: none;

vertical-align: top;

font-family: "simsun";

display: inline-block

}

.page span.prev_disabled {

cursor: default;

color: #ccc;

margin: 0 10px 0 0

}

.page a.current {

background-color: #f40;

border-color: #f40;

color: #fff;

font-weight: 700;

position: relative;

z-index: 1;

}

.page .extra {

display: inline-block;

margin-left: 10px;

height: 35px;

line-height: 35px;

color: #656565;

}

.page .page-num {

border: 1px solid #ededed;

height: 21px;

text-align: center;

width: 35px;

display: inline-block

}

.page .page-submit {

background-clip: padding-box;

border: 1px solid #ededed;

border-radius: 2px;

cursor: pointer;

height: 21px;

line-height: 21px;

text-align: center;

width: 43px;

display: inline-block

}

.page .page-submit:hover {

border-color: #f40;

color: #f40;

}

.page a:focus, .page a:hover {

border-color: #f40;

z-index: 1;

}

.loading {

margin: 30px 0;

text-align: center

}

p {

margin: 0

}

#page {

height: 40px;

padding: 20px 0px;

}

#page a {

display: block;

float: left;

margin-right: 10px;

padding: 2px 12px;

height: 24px;

border: 1px #cccccc solid;

background: #fff;

text-decoration: none;

color: #808080;

font-size: 12px;

line-height: 24px;

}

#page a:hover {

color: #077ee3;

border: 1px #077ee3 solid;

}

#page a.cur {

border: none;

background: #077ee3;

color: #fff;

}

#page p {

float: left;

padding: 2px 12px;

font-size: 12px;

height: 24px;

line-height: 24px;

color: #bbb;

border: 1px #ccc solid;

background: #fcfcfc;

margin-right: 8px;

}

#page p.pageRemark {

border-style: none;

background: none;

margin-right: 0px;

padding: 4px 0px;

color: #666;

}

#page p.pageRemark b {

color: red;

}

#page p.pageEllipsis {

border-style: none;

background: none;

padding: 4px 0px;

color: #808080;

}

.dates li {

font-size: 14px;

margin: 20px 0

}

.dates li span {

text-align: center

}

td {

font-size: 15px;

margin: 20px 0

}

希望本文所述对大家PHP程序设计有所帮助。

phppage类封装分页功能_PHP封装的page分页类定义与用法完整示例相关推荐

  1. phppage类封装分页功能_php封装的page分页类完整实例代码

    效果图 1.测试实例test.php header("Content-Type: text/html; charset=utf-8"); date_default_timezone ...

  2. phppage类封装分页功能_封装page分页类

    类: //分页工具类 class Page{ /* * 获取分页字符串 * @param1 string $uri,分页要请求的脚本url * @param3 int $counts,总记录数 * @ ...

  3. 分页功能的实现代码 与 分页查询

    数据库sql语句 分页查询: 1. SELECT (列名) FROM (表名) LIMIT (当前页数 - 1)* 每页几条数据,每页几条数据 列如:是第一页 每显示 5条数据 查询的表名 japan ...

  4. 用js实现分页功能以及利用xml实现分页功能——数据岛

    对于数据显示的分页,现在大多是直接通过数据库的动态读取来控制分页,这种方式相比js分页来说,效率低下.采用js分页,能够很好的控制数据的显示.目前大多是采用先预取全部的结果集,然后根据当前页数(pag ...

  5. php的类图怎么生成_PHP网站怎么划UML类图?

    匿名用户 1级 2017-01-16 回答 如果你尚未接触过uml,在你开始阅读前可以补充一些知识,我们收集了一些资源列在这篇文章的末尾. [inheritance 继承关系] php关键字exten ...

  6. php面向对象程序设计,PHP面向对象程序设计类的定义与用法简单示例

    本文实例讲述了PHP面向对象程序设计类的定义与用法.分享给大家供大家参考,具体如下: class Person { private $name; private $sex; private $age; ...

  7. phppage类封装分页功能_php显示页码分页类的封装

    本文实例为大家分享了php封装显示页码的分页类,供大家参考,具体内容如下 一.代码 conn.php class Mysql{ public function __construct(){ $this ...

  8. 前端分页功能(封装好的组件)

    1. 封装好的分页组件 //页码 <template><!-- 页码 --><div class="page"><el-paginatio ...

  9. java ajax实现分页代码,jQuery实现分页功能(含ajax请求、后台数据、附完整demo)...

    需求分析 1)需要首页,末页功能 2)有点击查看上一页,下一页功能 3)页码到当前可视页码最后一页刷新页面 实现思路 也是分为三部分处理 1)点击首页,末页直接显示第一页或者最后一页内容,当前页面为第 ...

最新文章

  1. 生活只是需要一种积极的态度
  2. spring MVC配置详解
  3. Learn Blockchains by Building One
  4. 「Ubuntu: Conda」Conda相关命令
  5. Vsftpd文件传输服务(本地用户访问)
  6. android 使用SharedPreferences保存对象
  7. linux安装vim plug, vim-plug 的安装和使用
  8. xwpftablecell设置字体样式_HTML的文字样式
  9. 在RedHat Linux系统中安装和配置snmp服务
  10. 20190906 On Java8 第十八章 字符串
  11. 如何解决Please ensure that adb is correctly located at......
  12. 一个将汉字转换成拼音的npm包
  13. 2021年国内PT站点汇总(中英文名称对照表)很全呦!
  14. July大神的大数据解决思路
  15. 谷歌浏览器chrome翻译插件完美解决开发者模式插件问题
  16. 区块链最可能大规模应用场景:社交网络和共享经济
  17. 美国硕士计算机机械专业排名,工科“三巨头”之一-机械工程的美国硕士申请全解答...
  18. 和在java和c语言中的那些事
  19. 简述windows计算机启动过程,计算机启动过程
  20. 格式化硬盘并安装Win10和Ubuntu双系统

热门文章

  1. 数据结构——树的理解路线(总)
  2. vue 组件之间数据传递(七)
  3. JAVA多线程程序ProgressBar
  4. TCP/IP 协议栈 -- 编写UDP客户端注意细节
  5. Confluent Platform 3.0支持使用Kafka Streams实现实时的数据处理(最新版已经是3.1了,支持kafka0.10了)...
  6. LockSupport的park和unpark
  7. 采用java信号量(semaphore)让线程轮流打印
  8. 【海淘域名】GoDaddy账户被锁定后的解决方法
  9. 一台服务器上部署多个Terracotta的方法
  10. 计算机专业的学生该选择日后的人生道路?继续从事IT还是考公务员……