Phpgoogle or baidu paging code. Copy the code as follows :? Php ** author: Xiaoxiang blog Time: 2009-11-26php technology group: 37304662 usage: include_oncePager.class.php; $ pagernewPager (); if (isset (
The code is as follows:
/**
Author: Xiaoxiang blog
Time:
2009-11-26
Php technology group:
37304662
Usage:
Include_once 'pager. class. php ';
$ Pager = new Pager ();
If (isset ($ _ GET ['Page'])
$ Pager-> setCurrentPage ($ _ GET ['Page']);
Else
$ Pager-> setCurrentPage (1 );
$ Pager-> setRecorbTotal (1000 );
$ Pager-> setBaseUri ("page. php? ");
Echo $ pager-> execute ();
**/
Class Pager {
/**
* Total number of int pages
**/
Protected $ pageTotal;
/**
* Int previous page
**/
Protected $ previous;
/**
* Int Next page
**/
Protected $ next;
/**
* Starting number of the int intermediate page
**/
Protected $ startPage;
/**
* Int intermediate page termination number
**/
Protected $ endPage;
/**
* Total number of int records
**/
Protected $ recorbTotal;
/**
* Int number of records per page
**/
Protected $ pageSize;
/**
* Int current display page
**/
Protected $ currentPage;
/**
* String base url
**/
Protected $ baseUri;
/**
* @ Returnstring get the base url address
*/
Public function getBaseUri (){
Return $ this-> baseUri;
}
/**
* @ Returnint get the current display page
*/
Public function getCurrentPage (){
Return $ this-> currentPage;
}
/**
* @ Returnint get the number of records displayed on each page
*/
Public function getPageSize (){
Return $ this-> pageSize;
}
/**
* @ Returnint get the total number of records
*/
Public function getRecorbTotal (){
Return $ this-> recorbTotal;
}
/**
* @ Paramstring $ baseUri: set the base url address
*/
Public function setBaseUri ($ baseUri ){
$ This-> baseUri = $ baseUri;
}
/**
* @ Paramint $ currentPage sets the current display page
*/
Public function setCurrentPage ($ currentPage ){
$ This-> currentPage = $ currentPage;
}
/**
* @ Paramint $ pageSize: set the number of records displayed on each page
*/
Public function setPageSize ($ pageSize ){
$ This-> pageSize = $ pageSize;
}
/**
* @ Paramint $ recorbTotal sets the total number of records to be retrieved.
*/
Public function setRecorbTotal ($ recorbTotal ){
$ This-> recorbTotal = $ recorbTotal;
}
/**
* Constructor
**/
Public function _ construct ()
{
$ This-> pageTotal = 0;
$ This-> previous = 0;
$ This-> next = 0;
$ This-> startPage = 0;
$ This-> endPage = 0;
$ This-> pageSize = 20;
$ This-> currentPage = 0;
}
/**
* Paging algorithm
**/
Private function arithmetic (){
If ($ this-> currentPage <1)
$ This-> currentPage = 1;
$ This-> pageTotal = floor ($ this-> recorbTotal/$ this-> pageSize) + ($ this-> recorbTotal % $ this-> pageSize> 0? 1-0 );
If ($ this-> currentPage> 1 & $ this-> currentPage> $ this-> pageTotal)
Header ('Location: '. $ this-> baseUri. 'page ='. $ this-> pageTotal );
$ This-> next = $ this-> currentPage + 1;
$ This-> previous = $ this-> currentPage-1;
$ This-> startPage = ($ this-> currentPage + 5)> $ this-> pageTotal? $ This-> pageTotal-10: $ this-> currentPage-5;
$ This-> endPage = $ this-> currentPage <5? 11: $ this-> currentPage + 5;
If ($ this-> startPage <1)
$ This-> startPage = 1;
If ($ this-> pageTotal <$ this-> endPage)
$ This-> endPage = $ this-> pageTotal;
}
/**
* Paging style
**/
Protected function pageStyle (){
$ Result = "total". $ this-> pageTotal. "page ";
If ($ this-> currentPage> 1)
$ Result. = "baseUri." page = 1 \ "> 1st page baseUri." page = $ this-> previous \ "> previous page ";
Else
$ Result. = "page 1st ";
For ($ I = $ this-> startPage; $ I <= $ this-> endPage; $ I ++ ){
If ($ this-> currentPage = $ I)
$ Result. = "$ I ";
Else
$ Result. = "baseUri." page = $ I \ "> $ I ";
}
If ($ this-> currentPage! = $ This-> pageTotal ){
$ Result. = "baseUri." page = $ this-> next \ "> next page ";
$ Result. = "baseUri." page = $ this-> pageTotal \ "> last page ";
} Else {
$ Result. = "Last page ";
}
Return $ result;
}
/**
* Execution page
**/
Public function execute (){
If ($ this-> baseUri! = "" & $ This-> recorbTotal = 0)
Return "";
$ This-> arithmetic ();
Return $ this-> pageStyle ();
}
}
?>
The http://www.bkjia.com/PHPjc/320801.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320801.htmlTechArticle code is as follows :? Php/** author: Xiaoxiang blog Time: 2009-11-26 php Technology Group: 37304662 usage: include_once 'pager. class. php '; $ pager = new Pager (); if (isset (...