Phpgoogle or baidu paging code

Source: Internet
Author: User
Php implements paging code for google and baidu. For more information, see. 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 ();
}
}
?>

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.