A very exquisite php paging class that can be directly applied to the paging system is a necessary tool for mysql database paging, you only need to embed class files and paging CSS styles to achieve exquisite paging. This is a simple, convenient, and fully functional paging class. you can change the CSS style file as needed to control the page color. using the php paging class, you can save yourself a lot of time, you only need to embed it in the paging area. The following describes how to use it:
1. wrap pager.css in the headers
The code is as follows:
2. instantiate the class on the page:
The code is as follows:
Include "pager. class. php ";
$ CurrentPage = isset ($ _ GET ['Page'])? $ _ GET ['Page']: 1;
// Die ($ CurrentPage );
$ MyPage = new pager (1300, intval ($ CurrentPage ));
$ PageStr = $ myPage-> GetPagerContent ();
// Echo $ pageStr;
$ MyPage = new pager (90, intval ($ CurrentPage ));
$ PageStr = $ myPage-> GetPagerContent ();
Echo $ pageStr;
?>
3. read mysql databases and paging computing files by yourself. For example:
$ Info = mysql_query ("select * from member order by id desc limit $ offset, $ info_num"); in this way, it can be transferred to the mysql database and the current page number.
The following are a total of three files: (1) index. php: Call the paging class, display the page (2) pager. class. php: php paging class (3366pager.css: css style beautification file
(1) index. php:
The code is as follows:
---- Paging demonstration -----
Include "pager. class. php ";
$ CurrentPage = isset ($ _ GET ['Page'])? $ _ GET ['Page']: 1;
// Die ($ CurrentPage );
$ MyPage = new pager (1300, intval ($ CurrentPage ));
$ PageStr = $ myPage-> GetPagerContent ();
// Echo $ pageStr;
$ MyPage = new pager (90, intval ($ CurrentPage ));
$ PageStr = $ myPage-> GetPagerContent ();
Echo $ pageStr;
?>
(2) pager. class. php:
The code is as follows:
/*
* PHP paging class
* @ Package Page
* @ Created 2013-03-27
* @ Modify 2013-03-27
* @ Link http://www.60ie.net
* Example:
$ MyPage = new Pager (1300, intval ($ CurrentPage ));
$ PageStr = $ myPage-> GetPagerContent ();
Echo $ pageStr;
*/
Class Pager {
Private $ pageSize = 10;
Private $ pageIndex;
Private $ totalNum;
Private $ totalPagesCount;
Private $ pageUrl;
Private static $ _ instance;
Public function _ construct ($ p_totalNum, $ p_pageIndex, $ p_pageSize = 10, $ p_initNum = 3, $ p_initMaxNum = 5 ){
If (! Isset ($ p_totalNum) |! Isset ($ p_pageIndex )){
Die ("pager initial error ");
}
$ This-> totalNum = $ p_totalNum;
$ This-> pageIndex = $ p_pageIndex;
$ This-> pageSize = $ p_pageSize;
$ This-> initNum = $ p_initNum;
$ This-> initMaxNum = $ p_initMaxNum;
$ This-> totalPagesCount = ceil ($ p_totalNum/$ p_pageSize );
$ This-> pageUrl = $ this-> _ getPageUrl ();
$ This-> _ initPagerLegal ();
}
/**
* Obtain the current URL string for page removal.
*
* @ Return String URL String
*/
Private function _ getPageUrl (){
$ CurrentUrl = $ _ SERVER ["REQUEST_URI"];
$ ArrUrl = parse_url ($ CurrentUrl );
$ UrlQuery = $ arrUrl ["query"];
If ($ urlQuery ){
$ UrlQuery = ereg_replace ("(^ | &) page =". $ this-> pageIndex, "", $ urlQuery );
$ CurrentUrl = str_replace ($ arrUrl ["query"], $ urlQuery, $ CurrentUrl );
If ($ urlQuery ){
$ CurrentUrl. = "& page ";
}
Else $ CurrentUrl. = "page ";
} Else {
$ CurrentUrl. = "? Page ";
}
Return $ CurrentUrl;
}
/*
* Set the validity of page parameters
* @ Return void
*/
Private function _ initPagerLegal ()
{
If ((! Is_numeric ($ this-> pageIndex) | $ this-> pageIndex <1)
{
$ This-> pageIndex = 1;
} Elseif ($ this-> pageIndex> $ this-> totalPagesCount)
{
$ This-> pageIndex = $ this-> totalPagesCount;
}
}
// $ This-> pageUrl }={$ I}
// {$ This-> CurrentUrl }={$ this-> TotalPages}
Public function GetPagerContent (){
$ Str ="
";
// Homepage previous page
If ($ this-> pageIndex = 1)
{
$ Str. = "homepage". "\ n ";
$ Str. = "previous page". "\ n". "\ n ";
} Else
{
$ Str. = "pageUrl} = 1 'class = 'tids' title = 'homepage'> homepage". "\ n ";
$ Str. = "pageUrl} = ". ($ this-> pageIndex-1 ). "'class = 'tids' title = 'preput'> Previous Page ". "\ n ". "\ n ";
}
/*
Page paging logic after the beginning and end
*/
// Below 10 pages (inclusive)
$ Currnt = "";
If ($ this-> totalPagesCount <= 10)
{
For ($ I = 1; $ I <= $ this-> totalPagesCount; $ I ++)
{
If ($ I ==$ this-> pageIndex)
{$ Currnt = "class = 'current '";}
Else
{$ Currnt = "";}
$ Str. = "pageUrl }={$ I} '{$ currnt}> $ I". "\ n ";
}
} Else // more than 10 pages
{If ($ this-> pageIndex <3) // The current page is smaller than 3
{
For ($ I = 1; $ I <= 3; $ I ++)
{
If ($ I ==$ this-> pageIndex)
{$ Currnt = "class = 'current '";}
Else
{$ Currnt = "";}
$ Str. = "pageUrl }={$ I} '{$ currnt}> $ I". "\ n ";
}
$ Str. = "...... "." \ N ";
For ($ I = $ this-> totalPagesCount-3 + 1; $ I <= $ this-> totalPagesCount; $ I ++) // Function 1
{
$ Str. = "pageUrl }={$ I} '> $ I". "\ n ";
}
} Elseif ($ this-> pageIndex <= 5) // 5> = current page> = 3
{
For ($ I = 1; $ I <= ($ this-> pageIndex + 1); $ I ++)
{
If ($ I ==$ this-> pageIndex)
{$ Currnt = "class = 'current '";}
Else
{$ Currnt = "";}
$ Str. = "pageUrl }={$ I} '{$ currnt}> $ I". "\ n ";
}
$ Str. = "...... "." \ N ";
For ($ I = $ this-> totalPagesCount-3 + 1; $ I <= $ this-> totalPagesCount; $ I ++) // Function 1
{
$ Str. = "pageUrl }={$ I} '> $ I". "\ n ";
}
} Elseif (5 <$ this-> pageIndex & $ this-> pageIndex <= $ this-> totalPagesCount-5) // The current page is larger than 5 and smaller than the total page number-5
{
For ($ I = 1; $ I <= 3; $ I ++)
{
$ Str. = "pageUrl }={$ I} '> $ I". "\ n ";
}
$ Str. = "...... ";
For ($ I = $ this-> pageIndex-1; $ I <= $ this-> pageIndex + 1 & $ I <= $ this-> totalPagesCount-5 + 1; $ I ++)
{
If ($ I ==$ this-> pageIndex)
{$ Currnt = "class = 'current '";}
Else
{$ Currnt = "";}
$ Str. = "pageUrl }={$ I} '{$ currnt}> $ I". "\ n ";
}
$ Str. = "...... ";
For ($ I = $ this-> totalPagesCount-3 + 1; $ I <= $ this-> totalPagesCount; $ I ++)
{
$ Str. = "pageUrl }={$ I} '> $ I". "\ n ";
}
} Else
{
For ($ I = 1; $ I <= 3; $ I ++)
{
$ Str. = "pageUrl }={$ I} '> $ I". "\ n ";
}
$ Str. = "...... "." \ N ";
For ($ I = $ this-> totalPagesCount-5; $ I <= $ this-> totalPagesCount; $ I ++) // Function 1
{
If ($ I ==$ this-> pageIndex)
{$ Currnt = "class = 'current '";}
Else
{$ Currnt = "";}
$ Str. = "pageUrl }={$ I} '{$ currnt}> $ I". "\ n ";
}
}
}
/*
Page paging logic ends after the beginning and end
*/
// Last page of The Next page
If ($ this-> pageIndex = $ this-> totalPagesCount)
{
$ Str. = "\ n". "next page". "\ n ";
$ Str. = "Last Page". "\ n ";
} Else
{
$ Str. = "\ n ". "pageUrl} = ". ($ this-> pageIndex + 1 ). "'class = 'tids' title = 'next page'> next page ". "\ n ";
$ Str. = "pageUrl }={$ this-> totalPagesCount} 'class = 'tids' title = 'Last page'> last page'." \ n ";
}
$ Str. ="
";
Return $ str;
}
/**
* Obtain an instance
* @ Return
*/
// Static public function getInstance (){
// If (is_null (self: $ _ instance )){
// Self: $ _ instance = new pager ();
//}
// Return self: $ _ instance;
//}
}
?>
(3) pager.css:
The code is as follows:
Body, html {padding: 0px; margin: 0px; color: #333333; font-family: "", Arial, Lucida, Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 150% ;}
H1, h2, h3, h4, h5, h6, ul, li, dl, dt, dd, form, img, p, label {margin: 0; padding: 0; border: none; list-style-type: none ;}
/** Front-end paging style **/
. Pagination {margin: 10px 0 0; padding: 5px 0; text-align: rightright; height: 20px; line-height: 20px; font-family: Arial, Helvetica, sans-serif, "";}
. Pagination a {margin-left: 2px; padding: 2px 7px 2px ;}
. Pagination. dot {border: medium none; padding: 4px 8px}
. Pagination a: link,. Pagination a: visited {border: 1px solid # dedede; color: #696969; text-decoration: none ;}
. Pagination a: hover ,. pagination a: active ,. pagination. current: link ,. pagination. current: visited {border: 1px solid # dedede; color: # fff; background-color: # ff6600; background-image: none; border: # ff6600 solid 1px ;}
. Pagination. selectBar {border: # dedede solid 1px; font-size: 12px; width: 95px; height: 21px; line-height: 21px; margin-left: 10px; display: inline}
. Pagination a. tips {_ padding: 4px 7px 1px ;}
Reprinted: http://60ie.net/article/8/365.html