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 mysql_field_name ($ result, $ I );
Echo' | ';}Echo'
';While ($ row = mysql_fetch_assoc ($ result )){Echo'
';Foreach ($ row as $ key => $ value){Echo'
';
Echo $ value;
Echo' | ';}Echo'
';}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: