Practical and simple PHP paging set including usage

Source: Internet
Author: User
After collecting three PHP paging methods, there will always be one suitable for you.

After collecting three PHP paging methods, there will always be one suitable for you.

Method 1:

The Code is as follows:


/*
The paging class is used to display multiple data entries by page.
Version: 1.0
Date: 2013-10-20
*/

/*
The call is very convenient. You can connect to the database and directly transmit the SQL string queried by the person. You can also specify the number of data entries displayed on each page.
For example, $ pages = new Page ('select * FROM 'zy _ common_member '');
Or $ pages = new Page ('select * FROM 'zy _ common_member '', 10 );
*/
Class Page {
Private $ curPage;
Private $ totalPages; // The total number of data pages displayed.
Private $ dispNum; // number of data entries per page
Private $ queryStr; // The queried SQL statement
Private $ limitStr; // The limit control statement after the query statement

/*
Constructor
$ QueryStr SQL statement for Data Query
$ DispNum number of data entries per page
*/
Public function _ construct ($ queryStr = '', $ dispNum = 10 ){
$ Result = mysql_query ($ queryStr );
$ TotalNum = mysql_num_rows ($ result );
$ This-> dispNum = $ dispNum;
$ This-> totalPages = ceil ($ totalNum/$ dispNum );
$ This-> queryStr = $ queryStr;

$ Temp = (isset ($ _ GET ["curPage"])? $ _ GET ["curPage"]: 1 );
$ This-> setCurPage ($ temp );

$ This-> showCurPage ();
$ This-> showFoot ();
}

/* Display the data content on the current page */
Private function showCurPage (){
$ This-> limitStr = 'limit'. ($ this-> curPage-1) * $ this-> dispNum). ','. $ this-> dispNum;
// Echo $ this-> queryStr. $ this-> limitStr;
$ Result = mysql_query ($ this-> queryStr. $ this-> limitStr );

If (! $ Result)
{
If ($ this-> totalPages> 0)
{
Echo 'query error '.'
';
}
Else
{
Echo 'no data '.'
';
}
Return;
}
$ Cols = mysql_num_fields ($ result );

Echo'



















';Echo' ';For ($ I = 0; $ I <$ cols; $ I ++){Echo' ';}Echo' ';While ($ row = mysql_fetch_assoc ($ result )){Echo' ';Foreach ($ row as $ key => $ value){Echo' ';}Echo' ';}Echo'
';
Echo mysql_field_name ($ result, $ I );
Echo'
';
Echo $ value;
Echo'
';
}

Private function setCurPage ($ curPage ){
If ($ curPage <1)
{
$ CurPage = 1;
}
Else if ($ curPage> $ this-> totalPages)
{
$ CurPage = $ this-> totalPages;
}
$ This-> curPage = $ curPage;
}

/*
Display page footer information
Such as the home page, Previous Page, next page, and last page.
*/
Private function showFoot (){
Echo 'homepage ';
Echo 'curpage-1). '"> Previous Page ';
Echo 'curpage + 1). '"> next page ';
Echo 'totalpages. '"> last page ';
}

}

?>


Method 2:

The Code is as follows:

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.