Nice PHP paging class

Source: Internet
Author: User

<? Php
Class Pager {
// The generated page number (in fact, you do not need to use it)
Var $ pageNumber = '';

// Total number of entries to be classified
Var $ totalItems = 0;
// Data connection problems
Var $ conn;
Var $ SQL;
// Several entries are displayed on each page.
Var $ itemsPerPage = 3;

// Total number of pages
Var $ totalPageNumber = 0;
// Current page number!
Var $ currentPageNumber = 1;

// Display several page numbers on a page
Var $ length = 10;


// The url to be paged
Var $ url = '';
Function Pager ($ conn, $ SQL, $ currentPageNumber, $ itemsPerPage, $ length, $ url ){
$ This-> currentPageNumber = $ currentPageNumber;
$ This-> conn = $ conn;
$ This-> SQL = $ SQL;
$ This-> itemsPerPage = $ itemsPerPage;
$ This-> length = $ length;
$ This-> url = $ url;
$ This-> url. = (stristr ($ this-> url ,'? ')! = False )? '&':'? '; // The Url contains "? "Add" & "add "? "
$ This-> getTotalPageNumber ();
}
Function getTotalItems (){
// For adodb
$ Rs = $ this-> conn-> Execute ($ this-> SQL );
$ This-> totalItems = $ rs-> RecordCount ();
Return $ this-> totalItems;
}
Function getTotalPageNumber (){
$ This-> totalPageNumber = ceil ($ this-> getTotalItems ()/$ this-> itemsPerPage );
Return $ this-> totalPageNumber;
}

// The start value of LIMIT start and length in SQL
Function getLimitStart (){
$ Start = ($ this-> currentPageNumber-1) * $ this-> itemsPerPage;
Return $ start;
}
// LIMIT start in SQL, length in length
Function getLimitItems (){
Return $ this-> itemsPerPage;
}
Function getRsPerPage (){
$ ModiSQL = $ this-> SQL. "limit". $ this-> getLimitStart (). ",". $ this-> getLimitItems ();
// I use adodb.
$ ModiRS = $ this-> conn-> Execute ($ modiSQL );
$ Arr = $ modiRS-> GetArray ();
Return $ arr;
}

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.