Home > Backend Development > PHP Tutorial > PHP simple paging class implementation method_PHP tutorial

PHP simple paging class implementation method_PHP tutorial

WBOY
Release: 2016-07-13 10:06:05
Original
857 people have browsed it

PHP simple paging class implementation method

This article mainly introduces the PHP simple paging class implementation method, and examples analyze the PHP paging class implementation skills, which has certain reference value. Friends in need can refer to it

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:

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 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.

www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template