PHP simple paging class implementation method,
The example in this article describes the implementation method of simple paging class in PHP. Share it with everyone for your reference. The details are as follows:
Copy code The code is as follows:
class PageModel {
/**
* Get paginated array
* @param unknown $page current page number
* @param unknown $goodsCount Total number of goods
* @param unknown $pageLength Number of pages displayed on each page
*/
Public static function getPageArr($page, $goodsCount, $pageCountLength, $pageLength) {
//Total number of 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);
}
//The total number of pages is displayed on one page
If ($allPageCount <= $pageCountLength) {
for ($i = 0; $i < $allPageCount; $i ++) {
$arr[] = array('page' => $i + 1);
return $arr;
//Length before and after
$halfLength = floor($pageCountLength / 2);
// Because it is too small, so put it in the original position, on the left
If ($page <= $halfLength) {
$arr = array();
for ($i = 0; $i < $pageCountLength; $i ++) {
$arr[] = array('page' => $i + 1);
return $arr;
//If it is too large, only the edge will be fetched. If it exceeds the limit, only the edge will be fetched
If ($page > $allPageCount - floor($pageCountLength / 2)) {
for ($i = -$pageCountLength; $i < 0; $i ++) {
$arr[] = array('page' => $allPageCount + $i + 1);
return $arr;
//The number in the middle, take out the number in the middle
for ($i = -$halfLength; $i < $pageCountLength - $halfLength; $i ++) {
$arr[] = array('page' => $page + $i);
}
return $arr;
}
}
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/960705.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/960705.html
TechArticle
php simple paging class implementation method, this article describes the php simple paging class implementation method. Share it with everyone for your reference. The details are as follows: Copy the code The code is as follows: class PageModel...