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

<"LIMIT ".($this->page-1)*$this->pagesize.",$this->pagesize";
     $this->url = $this->setUrl();
     $this->bothnum = 2;
   }
   //拦截器
   private function __get($_key) {
     return $this->$_key;
   }
   //获取当前页码
   private function setPage() {
     if (!empty($_GET['page'])) {
        if ($_GET['page'] > 0) {
          if ($_GET['page'] > $this->pagenum) {
             return $this->pagenum;
          } else {
             return $_GET['page'];
          }
        } else {
          return 1;
        }
     } else {
        return 1;
     }
   }
   //获取地址
   private function setUrl() {
     $_url = $_SERVER["REQUEST_URI"];
     $_par = parse_url($_url);
     if (isset($_par['query'])) {
        parse_str($_par['query'],$_query);
        unset($_query['page']);
        $_url = $_par['path'].'"'.$this->url.'&page='.$_page.'" rel="external nofollow" rel="external nofollow" >'.$_page.'</a> ';
     }
     $_pagelist .= ' <span class="me">'.$this->page.'</span> ';
     for ($i=1;$i<=$this->bothnum;$i++) {
      $_page = $this->page+$i;
        if ($_page > $this->pagenum) break;
        $_pagelist .= ' <a href="'.$this->url.'&page='.$_page.'" rel="external nofollow" rel="external nofollow" >'.$_page.'</a> ';
     }
     return $_pagelist;
   }
   //首页
   private function first() {
     if ($this->page > $this->bothnum+1) {
        return ' <a href="'.$this->url.'" rel="external nofollow" >1</a> ...';
     }
   }
   //上一页
   private function prev() {
     if ($this->page == 1) {
        return '<span class="disabled">上一页</span>';
     }
     return ' <a href="'.$this->url.'&page='.($this->page-1).'" rel="external nofollow" >上一页</a> ';
   }
   //下一页
   private function next() {
     if ($this->page == $this->pagenum) {
        return '<span class="disabled">下一页</span>';
     }
     return ' <a href="'.$this->url.'&page='.($this->page+1).'" rel="external nofollow" >下一页</a> ';
   }
   //尾页
   private function last() {
     if ($this->pagenum - $this->page > $this->bothnum) {
        return ' ...<a href="'.$this->url.'&page='.$this->pagenum.'" rel="external nofollow" >'.$this->pagenum.'</a> ';
     }
   }
   //分页信息
   public function showpage() {
     $_page .= $this->first();
     $_page .= $this->pageList();
     $_page .= $this->last();
     $_page .= $this->prev();
     $_page .= $this->next();
     return $_page;
   }
 }
"//img.jbzj.com/file_images/article/201707/201775104112746.jpg" alt="" />

使用说明:

<"_blank" href="https://www.jb51.net/Special/84.htm">php+mysql数据库操作入门教程》、《php+mysqli数据库程序设计技巧总结》、《php面向对象程序设计入门教程》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP网络编程技巧总结》及《php常见数据库操作技巧汇总》

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

标签:
PHP,分页类

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“PHP实现的分页类定义与用法示例”

暂无“PHP实现的分页类定义与用法示例”评论...