Php Generic pagination class _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.