Home > Backend Development > PHP Tutorial > One-page paging tool code implemented in PHP_PHP tutorial

One-page paging tool code implemented in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:42:03
Original
857 people have browsed it

The total number of pages is a wooden block with a certain length. This ruler slides on this wooden block. The premise is that the two ends of the ruler cannot exceed the wooden block: D. I found that what I had to do was to find the starting point of the ruler on the wooden block, based on the page variable passed in by the user. Haha, the key code is below:

Copy the code as follows
/**
* Treat the middle one as a sliding, fixed-length ruler
*
* Treat $this->_totalShowPages as a sliding, fixed-length ruler,
* Then $this-> ;_totalPages is a wooden block of a given length, and the ruler slides on this
* wooden block. There are two situations:
* 1. If the length of the ruler is greater than the length of the wooden block, then all page numbers will be output directly;
* 2. The length of the ruler is less than the length of the wooden block, then only the page with the length of the ruler will be found and output
* The starting point of the number——$start, $end;
*www.111cn.Net

* @Access protected
* @Return void
* @Exception none
*/
protected function _getShowPageNumber()
{
$pageHtml = '';
//Find the $start point
if($this->_curPage - 2 > 1) {
$start = $this->_curPage - 2;
} else {
$start = 1;
}
//Find $end point
$end = $start + $this->_totalShowPages;
if($end >= $this->_totalPages) {
$end = $this ->_totalPages;
$start = $end - $this->_totalShowPages; //The length of page display is guaranteed to be $this->_totalShowPages
}
if($start != 1) {
$pageHtml .= $this->_getPageHtml(1);
$preMore = $this->_curPage - $this->_totalShowPages;
if($preMore < 1) {
$preMore = 1;
}
$pageHtml .= $this->_getMorePageHtml($preMore);
}
for($page = $start; $page < $ end; $page ++) {
$pageHtml .= $this->_getPageHtml($page);
}
if($end != $this->_totalPages) {
$pageHtml .= $this->_getMorePageHtml($end);
}
$pageHtml .= $this->_getNormalPageHtml($this->_totalPages);

return $pageHtml ;
}

Code implementation of the first old idea:

 代码如下 复制代码
    /**
* Step by step
*
* @desc
*
* @Access protected
* @Return void
* @Exception none
*/
    protected function _getShowPageNumberTwo()
    {
    if($this->_curPage < $this->_totalShowPages) {
    for($page = 1; $page < $this->_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 < = $this->_totalPages; $page ++) {
    $pageHtml .= $this->_getPageHtml($page);
    }
    } else {
    $start = $this->_curPage - 2;
    $end = $this->_curPage + $this->_totalShowPages - 2;
    for($page = $start; $page < $end; $page ++) {
    $pageHtml .= $this->_getPageHtml($page);
    }
    $pageHtml .= $this->_getMorePageHtml($this->_curPage + $this->_totalShowPages - 2);
    $pageHtml .= $this->_getNormalPageHtml($this->_totalPages);
    }
    }
    
    return $pageHtml;
    }
 

示例图:

 

 

类文件下载:HPage.php (等我这个小类库完成了再一起放上 :D)。

更多详细内容请查看:http://www.bKjia.c0m/phper/php/56745.htm

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/670715.htmlTechArticle总的页数是一个长度一定的木块,这把尺子在这个木块上滑动,前提,尺子的两端不能超出木块:D。发现这么一来要做的事情就是去找这个...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template