PHP instance source code: PHP class for page turning

Source: Internet
Author: User
PHP instance source code: PHP class for page turning? PhpclassPage {var $ CountAll; // total number of records var $ CountPage; // number of records displayed per page var $ Link; // display the complete page information var $ ForPage; // Previous Page var $ NextPage; // Next Page var $ F

PHP instance source code: PHP class for page turning

Class Page {

Var $ CountAll; // total number of records
Var $ CountPage; // number of records displayed on each page
Var $ Link; // display the complete page information
Var $ ForPage; // Previous Page
Var $ NextPage; // Next page
Var $ FirstPage; // The first page
Var $ LastPage; // The Last Page
Var $ CurrPage; // page
Var $ PageNum; // total number of pages
Var $ Parameter; // Parameter
Var $ LimitNum; // not counting all records, but displaying some records. for example, a total of 100 records are displayed, but only the first 50 records are displayed.

Function Page ($ SQL, $ num = 30 ){

// Initialize and count the number of records
$ This-> CountPage = $ num;
Global $ mysql;
$ SQL = base64_decode ($ SQL );
$ Result = $ mysql-> Query ($ SQL );
If (0! = $ Mysql-> AffectedRows ()){
$ Row = $ mysql-> FetchArray ($ result );
$ This-> CountAll = $ row [0];
}
Else {
$ This-> CountAll = 0;
}
// Print \ "total $ this-> CountAll
\";
}

Function ListPage ($ SQL, $ page = 0, $ SQL _all, $ other ){
// Query, define variables, and obtain data

Global $ mysql;
// Print \ "SQL
\";
If (isset ($ this-> LimitNum) & $ this-> CountAll> $ this-> LimitNum ){
$ This-> CountAll = $ this-> LimitNum;
} // Update the total number of browsing records

$ SQL _src = $ SQL;
// If ($ page> 0 ){
$ SQL = base64_decode ($ SQL );
$ SQL _all = base64_decode ($ SQL _all );
$ SQL _src = $ SQL;
//}
// Echo $ SQL;
If ($ this-> CountAll % $ this-> CountPage) = 0) // count the total number of pages
$ Pagecount = (integer) ($ this-> CountAll/$ this-> CountPage );
Else
$ Pagecount = (integer) ($ this-> CountAll/$ this-> CountPage) 1;
$ This-> ageNum = $ pagecount;
If ($ page> $ this-> ageNum) // if the page number exceeds the total number of pages, set it to the maximum page number.
$ Page = $ this-> ageNum;
If ($ page <= 0) // if the page number is smaller than zero, set the page number to 1.
$ Page = 1;

If ($ this-> CountAll = 0)
{
$ This-> CurrPage = 0;
} Else {
$ This-> CurrPage = $ page;
}
$ First_start = ($ page-1) * $ this-> CountPage;
$ SQL = $ SQL. \ "limit \". $ first_start. \ ", \". $ this-> CountPage;
// Print \ "2sql
\";
$ Result = $ mysql-> Query ($ SQL );
If (0! = $ Mysql-> AffectedRows ()){
$ I = 0;
While ($ row = $ mysql-> FetchArray ($ result )){
$ Array [$ I] = $ row;
// Print \ "name: \". $ array [$ I] [Name]. \"
\";
$ I;
}
}

$ SQL = base64_encode ($ SQL _src );
$ SQL _all = base64_encode ($ SQL _all );
If ($ pagecount> 1 ){
If ($ page = 1 ){
$ Nextpage = $ page 1;
$ Forpage = 1;
$ This-> Link = \"Parameter. \ "& SQL _all = \". $ SQL _all. \"\". $ other. \ "\ '\" class = \ "button_a \" style = \ "width: 30; height: 22 \";>Parameter. \ "& SQL _all = \". $ SQL _all. \"\". $ other. \ "\ '\" class = \ "button_a \" style = \ "width: 30; height: 22 \";>\";

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.