PHP Simple Pagination class implementation method,
This paper introduces the implementation method of PHP simple paging class. Share to everyone for your reference. Specific as follows:
Copy CodeThe 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/960705.html www.bkjia.com true http://www.bkjia.com/PHPjc/960705.html techarticle PHP Simple Pagination class implementation method, this article describes the PHP simple paging class implementation method. Share to everyone for your reference. The following: Copy the code code as follows: Class Pagemodel ...