Php Generic paging class. Classshow_page {*** page output result ** @ varstring * var $ output; *** if this class is used, the default value is PHP_SELF ** @ varstring * var $ file; * ** the number of pages passes the variable. the variable is moclass 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. = 'File .'? '. $ This-> pvar.' = '. ($ current-10). ($ this-> varstr).' title = "top 10" ><<< ';
}
If ($ current> 1 ){
$ This-> output. = 'File .'? '. $ This-> pvar.' = '. ($ current-1). ($ this-> varstr).' title = "previous Page"> <';
}
$ 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. = ''. $ I.''; // output the current page number.
} Else {
$ This-> output. = 'File .'? '. $ This-> pvar.' = '. $ I. $ this-> varstr.' "> ['. $ I.'] '; // Number of output pages
}
}
If ($ current <$ this-> tpage ){
$ This-> output. = 'File .'? '. $ This-> pvar.' = '. ($ current + 1). ($ this-> varstr).' title = "next page" >>> ';
}
If ($ this-> tpage> 10 & ($ this-> tpage-$ current) >=10 ){
$ This-> output. = 'File .'? '. $ This-> pvar. '= '. ($ current + 10 ). ($ this-> varstr ). 'title = "Next 10 pages" >>> ';
}
}
}
/**
* 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. = '&'. $ 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;
}
}
Http://www.bkjia.com/PHPjc/445000.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445000.htmlTechArticleclass show_page {/*** page output result ** @ var string */var $ output;/*** use this class file, the default value is PHP_SELF ** @ var string */var $ file;/*** the number of pages that pass variables...