Paging is certainly very useful for developers. Today, let's take a look at an example of generating paging subscripts in PHP. I hope this article will help you. Paging is certainly very useful for developers. Today, let's take a look at an example of generating paging subscripts in PHP. I hope this article will help you.
Script ec (2); script
Example 1
The page selection effect of the webpage directly affects the user experience. There are many methods for similar functions. The main advantage of the method I write here is that the front and back ends are separated, and you can define the length and the number of lines in the page by yourself.
Test legend:
:
Example
/**
*
* @ Param $ page (1 to infinity)
* @ Param $ num: one page is displayed on the top of the data.
* @ Param $ total number of rows data rows
* @ Param $ length the maximum length of the subject
* @ Return array
*/
Public function PageDate ($ page, $ num, $ rows, $ length ){
// Initialize data
$ MaxPage = 0; // maximum page number
$ MinPage = 0; // minimum page number
$ ServerPage = 0; // the page number displayed in the drop-down list
$ PageData = array (); // set of all page numbers (select from the user drop-down list)
$ PageShowData = array (); // used to display the page number set of the lower mark
$ Page = intval ($ page );
If ($ rows = 0 ){
Return $ data = array (
'Page' => $ page,
'Maxpage' => $ MaxPage,
'Minpage' => $ MinPage,
'Serverpage' => $ ServerPage,
'Pagedata' => $ PageData,
'Pageshowdata' => $ PageShowData
);
}
// Obtain the maximum and minimum pages.
$ MaxPage = intval ($ rows/$ num );
$ Double = $ rows % $ num;
If ($ double> 0.000000001)
{
$ MaxPage + = 1;
}
$ MinPage = 1;
$ ServerPage = 1;
// Obtain all items on the page number
For ($ I = 1; $ I <= $ MaxPage; $ I ++ ){
$ PageData [$ I] = $ I;
}
// Correct the page number
If ($ page <$ MinPage ){
$ Page = 1;
}
If ($ page> $ MaxPage ){
$ Page = 1;
}
/* Generate the displayed page number tag */
// Generate the code on the left side quickly
If ($ page = $ MinPage ){
$ PageShowData [1] = $ page;
}
If ($ page> $ MinPage ){
$ PageShowData [1] = $ MinPage;
// $ PageShowData [2] = $ page-1; // <
$ PageShowData [2] = '<'; // <
If ($ page-2> $ MinPage ){
$ PageShowData [3] = $ page-2;
$ PageShowData [4] = $ page-1;
} Elseif ($ page-2 ==$ MinPage ){
$ PageShowData [3] = $ page-1;
}
// Confirm the selected page number code.
$ PageShowData [count ($ PageShowData) + 1] = $ page;
}
$ COUNT = count ($ PageShowData) + 1;
// Generate the code block on the right
If ($ page = $ MaxPage ){
Return $ data = array (
'Page' => $ page,
'Maxpage' => $ MaxPage,
'Minpage' => $ MinPage,
'Serverpage' => $ ServerPage,
'Pagedata' => $ PageData,
'Pageshowdata' => $ PageShowData
);
}
If ($ page <$ MaxPage ){
If ($ MaxPage-$ page> = 2 ){
$ J = 1;
For ($ I = $ COUNT; $ I <= $ length; $ I ++ ){
$ PageShowData [$ I] = $ page + $ j;
$ J ++;
If ($ PageShowData [$ I] ==$ MaxPage-1 ){
Break;
}
}
}
$ COUNT = count ($ PageShowData) + 1;
// $ PageShowData [$ COUNT] = $ page + 1; //>
$ PageShowData [$ COUNT] = '> ';
$ PageShowData [$ COUNT + 1] = $ MaxPage;
// Obtain the selected parameter
$ ServerPage = $ PageShowData [$ COUNT-1] + 1;
If ($ ServerPage> $ MaxPage ){
$ ServerPage = 1;
}
Return $ data = array (
'Page' => $ page,
'Maxpage' => $ MaxPage,
'Minpage' => $ MinPage,
'Serverpage' => $ ServerPage,
'Pagedata' => $ PageData,
'Pageshowdata' => $ PageShowData
);
}
}
Example 2
In this way, the page layout is seriously affected in some cases, and if too many pages are displayed on the article page, the user experience is also affected. Therefore, this tutorial cannot control the number of pages around dede, modify the {dede: pagebreak/} tag.
The situation is as follows:
This is divided into 15 pages, if more, don't feel like, the templates made by yourself are completely out of the way!
Effect after modification:
1
2
3
Modification method:
In the include/arc. archives. class. php class, this class is used to parse the content of the article.
Find
Function GetPagebreak ($ totalPage, $ nowPage, $ aid)
This is a static paging resolution method. In this method, find: for ($ I = 1; $ I <= $ totalPage $ I ++)
Add the following before this loop:
If ($ totalPage> = 8) {// This statement is executed when the number of pages is greater
$ Totallist = 7 + $ nowPage; // The number of pages to be displayed. If it is 10 pages, write 9.
If ($ totallist> $ totalPage ){
$ Totallist = $ totalPage;
}
$ D = $ nowPage;
$ Dqys = $ totallist-($ D-1 );
If ($ dqys <8 ){
$ D = $ totalPage-7;
}
} Else {
$ Totallist = $ totalPage;
$ D = 1;
}
Then change
For ($ I = 1; $ I <= $ totalPage; $ I ++) is for ($ I = $ d; $ I <= $ totallist; $ I ++)
This is the modification of Static Page pages. The dynamic method is the same as this method.