您好,欢迎访问一九零五行业门户网

php实现分页工具类分享_PHP

代码:
复制代码 代码如下:
    /**
    * 把中间的看成一个可以滑动的固定长度的尺子
    *
    * 把$this->_totalshowpages 当成一个可以滑动的固定长度尺子,
    * 然后$this->_totalpages就是一个给定长度的木块,尺子在这个
    * 木块上滑动。情况两种:
    * 1. 尺子长度大于木块长度,那么就直接输出所有的页码;
    * 2. 尺子长度小于木块长度,那么就只用找到输出这个尺子长度页
    * 数的起始点——$start, $end;
    * @access protected
    * @return void
    * @exception none
    */
    protected function _getshowpagenumber()
    {
    $pagehtml = '';
    //找到$start点
    if($this->_curpage - 2 > 1) {
    $start = $this->_curpage - 2;
    } else {
    $start = 1;
    }
    //找到$end 点
    $end = $start + $this->_totalshowpages;
    if($end >= $this->_totalpages) {
    $end = $this->_totalpages;
    $start = $end - $this->_totalshowpages; //保证页面显示的长度为$this->_totalshowpages
    }
    if($start != 1) {
    $pagehtml .= $this->_getpagehtml(1);
    $premore = $this->_curpage - $this->_totalshowpages;
    if($premore     $premore = 1;
    }
    $pagehtml .= $this->_getmorepagehtml($premore);
    }
    for($page = $start; $page     $pagehtml .= $this->_getpagehtml($page);
    }
    if($end != $this->_totalpages) {
    $pagehtml .= $this->_getmorepagehtml($end);
    }
    $pagehtml .= $this->_getnormalpagehtml($this->_totalpages);
return $pagehtml;
    }
第一种老想法的代码实现:
复制代码 代码如下:
    /**
    * 一步步的来
    *
    * @desc
    *
    * @access protected
    * @return void
    * @exception none
    */
    protected function _getshowpagenumbertwo()
    {
    if($this->_curpage _totalshowpages) {
    for($page = 1; $page _totalshowpages; $page ++) {
    $pagehtml .= $this->_getpagehtml($page);
    }
    $pagehtml .= $this->_getmorepagehtml($this->_totalshowpages);
    $pagehtml .= $this->_getnormalpagehtml($this->_totalpages);
    } else {
    $pagehtml .= $this->_getnormalpagehtml(1);
    if($this->_curpage == $this->_totalshowpages) {
    $pagehtml .= $this->_getmorepagehtml(1);
    } else {
    $pagehtml .= $this->_getmorepagehtml($this->_curpage - $this->_totalshowpages);
    }
    if($this->_curpage + $this->_totalshowpages >= $this->_totalpages) {
    for($page = $this->_totalpages - $this->_totalshowpages; $page _totalpages; $page ++) {
    $pagehtml .= $this->_getpagehtml($page);
    }
    } else {
    $start = $this->_curpage - 2;
    $end = $this->_curpage + $this->_totalshowpages - 2;
    for($page = $start; $page     $pagehtml .= $this->_getpagehtml($page);
    }
    $pagehtml .= $this->_getmorepagehtml($this->_curpage + $this->_totalshowpages - 2);
    $pagehtml .= $this->_getnormalpagehtml($this->_totalpages);
    }
    }
return $pagehtml;
    }
其它类似信息

推荐信息