Class show_page {
/**
* Page output result
*
* @ Var string
*/
Var $ output;
/**
* If this class is used, the default value is PHP_SELF.
*
* @ Var string
*/
Var $ file;
/**
* Page number transfer variable. The default value is 'P'
*
* @ Var string
*/
Var $ pvar = "p ";
/**
* Page size
*
* @ Var integer
*/
Var $ psize;
/**
* Current page
*
* @ Var ingeger
*/
Var $ curr;
/**
* Variable array to be passed
*
* @ Var array
*/
Var $ varstr;
/**
* Total number of pages
*
* @ Var integer
*/
Var $ tpage;
/**
* Paging settings
*
* @ Access public
* @ Param int $ pagesize page size
* @ Param int $ total number of records
* @ Param int $ current page number, which is automatically read by default
* @ Return void
*/
Function set ($ pagesize = 20, $ total, $ current = false ){
Global $ HTTP_SERVER_VARS, $ HTTP_GET_VARS;
$ This-> tpage = ceil ($ total/$ pagesize );
If (! $ Current) {$ current = $ HTTP_GET_VARS [$ this-> pvar];}
If ($ current> $ this-> tpage) {$ current = $ this-> tpage ;}
If ($ current <1) {$ current = 1 ;}
$ This-> curr = $ current;
$ This-> psize = $ pagesize;
If (! $ This-> file) {$ this-> file = $ HTTP_SERVER_VARS ['php _ SELF '];}
If ($ this-> tpage> 1 ){
If ($ current> 10 ){
$ This-> output. = '<a href ='. $ this-> file .'? '. $ This-> pvar. '= '. ($ current-10 ). ($ this-> varstr ). 'title = "top 10 pages"> & lt; </a> & nbsp ;';
}
If ($ current> 1 ){
$ This-> output. = '<a href ='. $ this-> file .'? '. $ This-> pvar. '= '. ($ current-1 ). ($ this-> varstr ). 'title = "previous Page"> & lt; </a> & nbsp ;';
}
$ Start = floor ($ current/10) * 10;
$ End = $ start + 9;
If ($ start <1) {$ start = 1 ;}
If ($ end> $ this-> tpage) {$ end = $ this-> tpage ;}
For ($ I = $ start; $ I <= $ end; $ I ++ ){
If ($ current = $ I ){
$ This-> output. = '<font color = "red">'. $ I. '</font> & nbsp;'; // output the current page number.
} Else {
$ This-> output. = '<a href = "'. $ this-> file .'? '. $ This-> pvar. '= '. $ I. $ this-> varstr. '"> ['. $ I. '] </a> & nbsp;'; // Number of output pages
}
}
If ($ current <$ this-> tpage ){
$ This-> output. = '<a href ='. $ this-> file .'? '. $ This-> pvar. '= '. ($ current + 1 ). ($ this-> varstr ). 'title = "Next Page"> & gt; </a> & nbsp ;';
}
If ($ this-> tpage> 10 & ($ this-> tpage-$ current) >=10 ){
$ This-> output. = '<a href ='. $ this-> file .'? '. $ This-> pvar. '= '. ($ current + 10 ). ($ this-> varstr ). 'title = "Next 10 pages"> & gt; </a> ';
}
}
}
/**
* Variable settings to be passed
*
* @ Access public
* @ Param array $ the variable to be passed by data, which is represented by an array. For more information, see the example above.
* @ Return void
*/
Function setvar ($ data ){
Foreach ($ data as $ k => $ v ){
$ This-> varstr. = '& amp;'. $ k. '='. urlencode ($ v );
}
}
/**
* Paging result output
*
* @ Access public
* @ Param bool $ return returns a string when it is true. Otherwise, it is output directly. By default, it is output directly.
* @ Return string
*/
Function output ($ return = false ){
If ($ return ){
Return $ this-> output;
} Else {
Echo $ this-> output;
}
}
/**
* Generate a Limit statement
*
* @ Access public
* @ Return string
*/
Function limit (){
Return ($ this-> curr-1) * $ this-> psize). ','. $ this-> psize;
}
}