The total number of pages is a piece of wood with a certain length. The ruler slides on the block. on the premise that the two ends of the ruler cannot exceed the block: D. What we need to do is to find the starting point of the ruler on the block, based on the page variable passed in by the user. Haha, below is the key code: the code is as follows: copy the code *** to regard the intermediate code as a possible
The total number of pages is a piece of wood with a certain length. The ruler slides on the block. on the premise that the two ends of the ruler cannot exceed the block: D. What we need to do is to find the starting point of the ruler on the block, based on the page variable passed in by the user. Haha, the key code is as follows: the code is as follows/*** to regard the intermediate code as
The total number of pages is a piece of wood with a certain length. The ruler slides on the block. on the premise that the two ends of the ruler cannot exceed the block: D. What we need to do is to find the starting point of the ruler on the block, based on the page variable passed in by the user. Haha, the key code is as follows:
The Code is as follows:
/**
* Think of the middle as a sliding fixed-length ruler.
*
* Consider $ this-> _ totalShowPages as a fixed-length ruler that can be slide,
* Then $ this-> _ totalPages is a block with a given length.
* Slide the block. Two scenarios:
* 1. If the ruler length is greater than the block length, all page numbers are output;
* 2. If the ruler length is smaller than the block length, you only need to find the output ruler length page.
* Starting point of the number -- $ start, $ end;
* Www.111cn. Net
* @ Access protected
* @ Return void
* @ Exception none
*/
Protected function _ getShowPageNumber ()
{
$ PageHtml = '';
// Locate $ start
If ($ this-> _ curPage-2> 1 ){
$ Start = $ this-> _ curPage-2;
} Else {
$ Start = 1;
}
// Locate the $ end point
$ End = $ start + $ this-> _ totalShowPages;
If ($ end >=$ this-> _ totalPages ){
$ End = $ this-> _ totalPages;
$ Start = $ end-$ this-> _ totalShowPages; // ensure that the displayed page length is $ this-> _ totalShowPages
}
If ($ start! = 1 ){
$ PageHtml. = $ this-> _ getPageHtml (1 );
$ PreMore = $ this-> _ curPage-$ this-> _ totalShowPages;
If ($ preMore <1 ){
$ PreMore = 1;
}
$ PageHtml. = $ this-> _ getMorePageHtml ($ preMore );
}
For ($ page = $ start; $ page <$ end; $ page ++ ){
$ PageHtml. = $ this-> _ getPageHtml ($ page );
}
If ($ end! = $ This-> _ totalPages ){
$ PageHtml. = $ this-> _ getMorePageHtml ($ end );
}
$ PageHtml. = $ this-> _ getNormalPageHtml ($ this-> _ totalPages );
Return $ pageHtml;
}
The Code Implementation of the first old idea:
The Code is as follows:
/**
* Step by step
*
* @ Desc
*
* @ Access protected
* @ Return void
* @ Exception none
*/
Protected function _ getShowPageNumberTwo ()
{
If ($ this-> _ curPage <$ this-> _ totalShowPages ){
For ($ page = 1; $ page <$ this-> _ totalShowPages; $ page ++ ){
$ PageHtml. = $ this-> _ getPageHtml ($ page );
}
$ PageHtml. = $ this-> _ getMorePageHtml ($ this-> _ totalShowPages );
$ PageHtml. = $ this-> _ getNormalPageHtml ($ this-> _ totalPages );
} Else {
$ PageHtml. = $ this-> _ getNormalPageHtml (1 );
If ($ this-> _ curPage = $ this-> _ totalShowPages ){
$ PageHtml. = $ this-> _ getMorePageHtml (1 );
} Else {
$ PageHtml. = $ this-> _ getMorePageHtml ($ this-> _ curPage-$ this-> _ totalShowPages );
}
If ($ this-> _ curPage + $ this-> _ totalShowPages >=$ this-> _ totalPages ){
For ($ page = $ this-> _ totalPages-$ this-> _ totalShowPages; $ page <= $ this-> _ totalPages; $ page ++ ){
$ PageHtml. = $ this-> _ getPageHtml ($ page );
}
} Else {
$ Start = $ this-> _ curPage-2;
$ End = $ this-> _ curPage + $ this-> _ totalShowPages-2;
For ($ page = $ start; $ page <$ end; $ page ++ ){
$ PageHtml. = $ this-> _ getPageHtml ($ page );
}
$ PageHtml. = $ this-> _ getMorePageHtml ($ this-> _ curPage + $ this-> _ totalShowPages-2 );
$ PageHtml. = $ this-> _ getNormalPageHtml ($ this-> _ totalPages );
}
}
Return $ pageHtml;
}
Example:
Class File Download: HPage. php (put it together after my small class library is completed: D ).
For more details, see: http://www.111cn.net/phper/php/56745.htm