- 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;
- ?>
- Php paging demonstration -bbs.it-home.org
- 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:
-
/*
- * PHP paging class
- * @ Package Page
- * @ Created 2013-03-27
- * @ Modify 2013-03-27
- * 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), php paging style file pager.css:
-
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 ;}
|