PHP Simple Pagination Class implementation method
This article mainly introduced the PHP simple pagination class implementation method, the example analysis PHP pagination class realization technique, has the certain reference value, needs the friend to refer to under
This paper introduces the implementation method of PHP simple paging class. Share to everyone for your reference. Specific as follows:
The code is as follows:
Class Pagemodel {
/**
* Get the number of page groups
* @param unknown $page current page number
* Total number of items @param unknown $goodsCount
* @param unknown $pageLength The number of pages displayed per page
*/
public static function Getpagearr ($page, $goodsCount, $pageCountLength, $pageLength) {
Total pages
$allPageCount = Ceil ($goodsCount/$pageLength);
If the page is always shorter than the length, set the page length to the total number of pages
if ($allPageCount <= $pageCountLength) {
$allPageCount = Ceil ($goodsCount/$pageLength);
}
Total page Count one page to finish
if ($allPageCount <= $pageCountLength) {
for ($i = 0; $i < $allPageCount; $i + +) {
$arr [] = Array (' page ' = + $i + 1);
}
return $arr;
}
The length before and after
$halfLength = Floor ($pageCountLength/2);
Because it is too small, so put the original position, left
if ($page <= $halfLength) {
$arr = Array ();
for ($i = 0; $i < $pageCountLength; $i + +) {
$arr [] = Array (' page ' = + $i + 1);
}
return $arr;
}
Too big, only take to the edge, beyond also only to the edge
if ($page > $allPageCount-floor ($pageCountLength/2)) {
for ($i =-$pageCountLength; $i < 0; $i + +) {
$arr [] = Array (' page ' = + $allPageCount + $i + 1);
}
return $arr;
}
The middle of the number, the middle of the take out
for ($i =-$halfLength; $i < $pageCountLength-$halfLength; $i + +) {
$arr [] = Array (' page ' = = $page + $i);
}
return $arr;
}
}
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/961080.html www.bkjia.com true http://www.bkjia.com/PHPjc/961080.html techarticle PHP Simple Pagination class implementation method This article mainly introduced the PHP simple pagination class implementation method, the example analysis PHP pagination class implementation technique, has the certain reference value, needs the friend to be able ...