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.