Php paging and calling methods
/**
- * Php paging code
- * Edit: bbs.it-home.org
- */
- Class Page {
- Private $ total; // total records
- Private $ pagesize; // The number of entries displayed on each page
- Private $ limit; // limit
- Private $ page; // The current page number.
- Private $ pagenum; // the total page number.
- Private $ url; // address
- Private $ bothnum; // The number of numeric pages on both sides
// Constructor initialization
- Public function _ construct ($ _ total, $ _ pagesize ){
- $ This-> total = $ _ total? $ _ Total: 1;
- $ This-> pagesize = $ _ pagesize;
- $ This-> pagenum = ceil ($ this-> total/$ this-> pagesize );
- $ This-> page = $ this-> setPage ();
- $ This-> limit = "LIMIT". ($ this-> page-1) * $ this-> pagesize. ", $ this-> pagesize ";
- $ This-> url = $ this-> setUrl ();
- $ This-> bothnum = 2;
- }
// Interceptor
- Private function _ get ($ _ key ){
- Return $ this-> $ _ key;
- }
// Obtain the current page number
- Private function setPage (){
- If (! Empty ($ _ GET ['Page']) {
- If ($ _ GET ['Page']> 0 ){
- If ($ _ GET ['Page']> $ this-> pagenum ){
- Return $ this-> pagenum;
- } Else {
- Return $ _ GET ['Page'];
- }
- } Else {
- Return 1;
- }
- } Else {
- Return 1;
- }
- }
// Obtain the address
- Private function setUrl (){
- $ _ Url = $ _ SERVER ["REQUEST_URI"];
- $ _ Par = parse_url ($ _ url );
- If (isset ($ _ par ['query']) {
- Parse_str ($ _ par ['query'], $ _ query );
- Unset ($ _ query ['Page']);
- $ _ Url = $ _ par ['path']. '? '. Http_build_query ($ _ query );
- }
- Return $ _ url;
- } // Numeric Directory
- Private function pageList (){
- For ($ I = $ this-> bothnum; $ I >=1; $ I --){
- $ _ Page = $ this-> page-$ I;
- If ($ _ page <1) continue;
- $ _ Pagelist. = 'URL. '& page ='. $ _ page. '">'. $ _ page .'';
- }
- $ _ Pagelist. = ''. $ this-> page .'';
- For ($ I = 1; $ I <= $ this-> bothnum; $ I ++ ){
- $ _ Page = $ this-> page + $ I;
- If ($ _ page> $ this-> pagenum) break;
- $ _ Pagelist. = 'URL. '& page ='. $ _ page. '">'. $ _ page .'';
- }
- Return $ _ pagelist;
- }
// Homepage
- Private function first (){
- If ($ this-> page> $ this-> bothnum + 1 ){
- Return 'URL. '"> 1 ...';
- }
- }
// Previous Page
- Private function prev (){
- If ($ this-> page = 1 ){
- Return 'previous page ';
- }
- Return 'URL. '& page ='. ($ this-> page-1). '"> Previous page ';
- }
// Next page
- Private function next (){
- If ($ this-> page ==$ this-> pagenum ){
- Return 'next page ';
- }
- Return 'URL. '& page ='. ($ this-> page + 1). '"> Next page ';
- }
// Last Page
- Private function last (){
- If ($ this-> pagenum-$ this-> page> $ this-> bothnum ){
- Return '... url.' & page = '. $ this-> pagenum.' "> '. $ this-> pagenum .'';
- }
- }
// Paging information
- Public function showpage (){
- $ _ Page. = $ this-> first ();
- $ _ Page. = $ this-> pageList ();
- $ _ Page. = $ this-> last ();
- $ _ Page. = $ this-> prev ();
- $ _ Page. = $ this-> next ();
- Return $ _ page;
- }
- }
- ?>
Paging style: Instructions for use:
- $ _ Page = new Page ($ _ total, $ _ pagesize); // where $ _ total indicates the total number of data sets, and $ _ pagesize indicates the number displayed on each page.
- ?>
|