Php simple paging Implementation Method

Source: Internet
Author: User
This article mainly introduces the php simple paging class implementation method. The example analyzes the php paging class implementation skills and has some reference value. For more information, see

This article mainly introduces the php simple paging class implementation method. The example analyzes the php paging class implementation skills and has some reference value. For more information, see

This article describes the php simple paging class implementation method. Share it with you for your reference. The details are as follows:

The Code is as follows:

Class PageModel {
/**
* Retrieve the paging Array
* @ Param unknown $ current page count
* @ Param unknown $ goodsCount Total number of items
* @ Param unknown $ pageLength: Number of displayed pages per 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 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, 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;
}
// It is too large. Only the edge is obtained. If it is exceeded, only the edge is obtained.
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.
For ($ I =-$ halfLength; $ I <$ pageCountLength-$ halfLength; $ I ++ ){
$ Arr [] = array ('page' => $ page + $ I );
}
Return $ arr;
}
}

I hope this article will help you with php programming.

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.