PHP Simple Page-by-class implementation method _php tips

Source: Internet
Author: User

This article illustrates the simple page-by-class implementation method of PHP. Share to everyone for your reference. Specifically as follows:

Copy Code code as follows:
Class Pagemodel {
/**
* Get a page-number group
* @param unknown $page The current number of pages
* @param unknown $goodsCount Total Merchandise
* @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 page show end
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 large, only to get to the edge, beyond the Edge
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.
for ($i =-$halfLength; $i < $pageCountLength-$halfLength; $i + +) {
$arr [] = Array (' page ' => $page + $i);
}
return $arr;
}
}

I hope this article will help you with your PHP program design.

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.