Pagination page numbering display algorithm
Copy CodeThe code is as follows:
/**
* Get HTML content for pagination
* @param integer $page current page
* Total number of pages $pages @param integer
* @param string $url The last page of the URL address appended with ' &page=x ' after the URL
*
* @return string HTML content;
*/
public static function getpagehtml ($page, $pages, $url) {
Maximum number of pages to display
$_pagenum = 5;
The current page is less than 1 is 1
$page = $page <1?1: $page;
The current page is greater than the total number of pages
$page = $page > $pages? $pages: $page;
The current page is a small page
$pages = $pages < $page? $page: $pages;
Calculate Start Page
$_start = $page-floor ($_PAGENUM/2);
$_start = $_start<1? 1: $_start;
Calculate End Page
$_end = $page + Floor ($_PAGENUM/2);
$_end = $_end> $pages? $pages: $_end;
The number of page numbers currently displayed is not large enough to adjust the 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;
}
Right adjustment
if ($_curpagenum<$_pagenum && $_end< $pages) {
$_end = $_end + ($_pagenum-$_curpagenum);
$_end = $_end> $pages? $pages: $_end;
}
$_pagehtml = '
';
/*if ($_start = = 1) {
$_pagehtml. = '
- «
';
}else{
$_pagehtml. = '
- «
';
}*/
if ($page >1) {
$_pagehtml. = '
- «
';
}
for ($i = $_start; $i <= $_end; $i + +) {
if ($i = = $page) {
$_pagehtml. = '
- '. $i. '
';
}else{
$_pagehtml. = '
- '. $i. '
';
}
}
/*if ($_end = = $pages) {
$_pagehtml. = '
- »
';
}else{
$_pagehtml. = '
- »
';
}*/
if ($page <$_end) {
$_pagehtml. = '
- »
';
}
$_pagehtml. = '
';
Echo $_pagehtml;
}
http://www.bkjia.com/PHPjc/755839.html www.bkjia.com true http://www.bkjia.com/PHPjc/755839.html techarticle pagination page number display algorithm copy code code as follows:/** * Get HTML content for pagination * @param integer $page current page * @param integer $pages Total pages * @param string $url jump ur ...