This article illustrates the simple page-by-class implementation method of PHP. Share to everyone for your reference. Specifically as follows:
Copy Code code as follows:
Class Pagemodel {
/**
* Get a page-number group
* @param unknown $page The current number of pages
* @param unknown $goodsCount Total Merchandise
* @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 page show end
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 large, only to get to the edge, beyond the Edge
if ($page > $allPageCount-floor ($pageCountLength/2)) {
for ($i =-$pageCountLength; $i < 0; $i + +) {
$arr [] = Array (' page ' => $allPageCount + $i + 1);
}
return $arr;
}
The middle number, take out the middle.
for ($i =-$halfLength; $i < $pageCountLength-$halfLength; $i + +) {
$arr [] = Array (' page ' => $page + $i);
}
return $arr;
}
}
I hope this article will help you with your PHP program design.