Home > Backend Development > PHP Tutorial > Beautiful paging method implemented in php_PHP tutorial

Beautiful paging method implemented in php_PHP tutorial

WBOY
Release: 2016-07-13 10:32:13
Original
917 people have browsed it

Paging page number display algorithm

Copy code The code is as follows:

/**
* Get paginated HTML content
* @param integer $page current page
* @param integer $pages total number of pages
* @param string $url jump url address The last page number starts with '&page=x' appended to the end of the url
*
* @return string HTML content;
*/
public static function getPageHtml($page , $pages, $url){
//The maximum number of page numbers to display
$_pageNum = 5;
//If the current page is less than 1, it is 1
$page = $page<1?1 :$page;
//If the current page is greater than the total number of pages, the total number of pages is
$page = $page > $pages ? $pages : $page;
//If the number of pages is less than the current page For the current page
$pages = $pages < $page ? $page : $pages;

//Calculate the start page
$_start = $page - floor($_pageNum/2);
$_start = $_start<1 ? 1 : $_start;
//Calculate the end page
$_end = $page + floor($_pageNum/2);
$_end = $_end> $pages? $pages : $_end;

//The number of pages currently displayed is not enough for the maximum number of pages. Adjust left and right
$_curPageNum = $_end-$_start+1;
/ /Left adjustment
if($_curPageNum<$_pageNum && $_start>1){
$_start = $_start - ($_pageNum-$_curPageNum);
$_start = $_start<1 ? 1 : $_start;
$_curPageNum = $_end-$_start+1;
}
//Adjust right
if($_curPageNum<$_pageNum && $_end<$pages){
$ _end = $_end + ($_pageNum-$_curPageNum);
$_end = $_end>$pages? $pages : $_end;
}

$_pageHtml = '';
echo $_pageHtml;
}

Beautiful paging method implemented in php_PHP tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/755839.htmlTechArticlePaging page number display algorithm Copy code code as follows: /** * Get paginated HTML content* @param integer $page Current page* @param integer $pages Total number of pages* @param string $url Jump ur...
Related labels:
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