PHP Simple page Pagination class implementation Method _php tutorial

Source: Internet
Author: User
Tags php programming

PHP Simple Pagination Class implementation method


This article mainly introduced the PHP simple pagination class implementation method, the example analysis PHP pagination class realization technique, has the certain reference value, needs the friend to refer to under

This paper introduces the implementation method of PHP simple paging class. Share to everyone for your reference. Specific as follows:

The code is as follows:

Class Pagemodel {
/**
* Get the number of page groups
* @param unknown $page current page number
* Total number of items @param unknown $goodsCount
* @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 one page to finish
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 big, only take to the edge, beyond also only to the edge
if ($page > $allPageCount-floor ($pageCountLength/2)) {
for ($i =-$pageCountLength; $i < 0; $i + +) {
$arr [] = Array (' page ' = + $allPageCount + $i + 1);
}
return $arr;
}
The middle of the number, the middle of the take out
for ($i =-$halfLength; $i < $pageCountLength-$halfLength; $i + +) {
$arr [] = Array (' page ' = = $page + $i);
}
return $arr;
}
}

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/961080.html www.bkjia.com true http://www.bkjia.com/PHPjc/961080.html techarticle PHP Simple Pagination class implementation method This article mainly introduced the PHP simple pagination class implementation method, the example analysis PHP pagination class implementation technique, has the certain reference value, needs the friend to be able ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.