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:
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 in 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, put it in the original position, 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 middle number, take out the middle number
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/961080.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/961080.htmlTechArticlephp simple paging class implementation method This article mainly introduces the php simple paging class implementation method, and analyzes php paging with examples. Class implementation skills have certain reference value. Friends who need them can...