侯体宗的博客
  • 首页
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

PHP封装的page分页类定义与用法完整示例

php  /  管理员 发布于 7年前   199

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

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

1. 测试实例test.php

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;?>            

报表

$v) {?>
ID 商品编号 订阅状态 商品状态 修改时间 创建时间
$showrow) {//总记录数大于每页显示数,显示分页 $page = new page($total, $showrow, $curpage, $url, 3); echo $page->myde_write(); } ?>
阿里巴巴:https://www.taobao.com

2. 封装的page分页类page.class.php

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 "page_replace(1) . "' title='首页'>首页";    } else {      return "

首页

"; } } //上一页 private function myde_prev() { if ($this->myde_page != 1) { return "page_replace($this->myde_page - 1) . "' title='上一页'>上一页"; } else { return "

上一页

"; } } //下一页 private function myde_next() { if ($this->myde_page != $this->myde_page_count) { return "page_replace($this->myde_page + 1) . "' title='下一页'>下一页"; } else { return"

下一页

"; } } //尾页 private function myde_last() { if ($this->myde_page != $this->myde_page_count) { return "page_replace($this->myde_page_count) . "' title='尾页'>尾页"; } 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.="page_replace($i) . "' title='第" . $i . "页' class='cur'>$i"; } else { $str.="page_replace($i) . "' title='第" . $i . "页'>$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相关内容感兴趣的读者可查看本站专题:《php+mysql数据库操作入门教程》、《php+mysqli数据库程序设计技巧总结》、《php面向对象程序设计入门教程》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP网络编程技巧总结》及《php常见数据库操作技巧汇总》

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

您可能感兴趣的文章:

  • PHP封装的完整分页类示例
  • thinkPHP框架可添加js事件的分页类customPage.class.php完整实例
  • php封装的page分页类完整实例
  • php自定义分页类完整实例
  • php封装的page分页类完整实例代码


  • 上一条:
    PHP基于PDO扩展操作mysql数据库示例
    下一条:
    PHP时间日期增减操作示例【date strtotime实现加一天、加一月等操作】
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 用Time Warden监控PHP中的代码处理时间(0个评论)
    • 在PHP中使用array_pop + yield实现读取超大型目录功能示例(0个评论)
    • Property Hooks RFC在PHP 8.4中越来越接近现实(0个评论)
    • 近期文章
    • 在windows10中升级go版本至1.24后LiteIDE的Ctrl+左击无法跳转问题解决方案(0个评论)
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(95个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-11
    • 2017-12
    • 2018-01
    • 2018-02
    • 2018-03
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-09
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    • 2024-05
    • 2024-06
    • 2024-07
    • 2024-09
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客