PHP simple paging class implementation method, _PHP tutorial

WBOY
Release: 2016-07-13 10:06:17
Original
860 people have browsed it

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

Related labels:
php
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