A pagination class for an instance phpmysql template .? Php Tutorial ** template paging class, derived from the database tutorial paging method of the easp tutorial, is an easp independent php version * supports dynamic and static paging mode * easp official website easp. leng
/*
* The template paging class is derived from the paging method of the database tutorial in the easp tutorial. it is an independent php version of the easp paging.
* Supports dynamic and static paging.
* Easp official website http://easp.lengshi.com/
* Author: Zhong Jingjing
* Date: 2010-11-3
* Email: zhongjingjing@gmail.com
* Blog: http://blog.zaimer.com
* Page ([total number of records = 1], [page size = 20], [current page = 1], [display page size = 6], [paging parameter = 'page'], [paging link = current page], [static = false])
* Dynamic:
* Simple usage:
* $ Page = new page (50 );
* $ Page-> setpager ('zjj ','
Total {recordcount} items on the {pageindex} page/total {pagecount} page: {first} {prev} {list} {next} {last} to the {jump} page
', Array ("listlong" => "6", "first" => "homepage", "last" => "last page ", "prev" => "previous page", "next" => "next page", "list" => "page *", "jump" => "select "));
* Echo $ page-> getpager ('zjj ');
* Full parameter usage:
* $ Page = new page (50, 20, 'page', 'prrr. php', false );
* $ Page-> setpager ('zjj ','
Total {recordcount} items on the {pageindex} page/total {pagecount} page: {first} {prev} {list} {next} {last} to the {jump} page
', Array ("listlong" => "6", "first" => "homepage", "last" => "last page ", "prev" => "previous page", "next" => "next page", "list" => "page *", "jump" => "select "));
* Echo $ page-> getpager ('zjj ');
* Static:
* $ Page = new page(50,20,1,6, 'page', 'prrr?page=.html ', true );
* $ Page-> setpager ('zjj ','
Total {recordcount} items on the {pageindex} page/total {pagecount} page: {first} {prev} {list} {next} {last} to the {jump} page
', Array ("listlong" => "6", "first" => "homepage", "last" => "last page ", "prev" => "previous page", "next" => "next page", "list" => "page *", "jump" => "select "));
* Echo $ page-> getpager ('zjj ');
*/
Class page {
Private $ page_size; // Number of Entries displayed on each page
Private $ total_size; // total number of items
Private $ current_page; // the currently selected page
Private $ sub_pages; // The number of pages displayed each time
Private $ total_pages; // total number of pages
Private $ page_tpl = array (); // pagination Template
Private $ pageparam;
Private $ pagelink;
Private $ static;
Function _ construct ($ total_size = 1, $ page_size = 20, $ current_page = 1, $ sub_pages = 6, $ pageparam = 'page', $ pagelink = '', $ static = false ){
$ This-> page_size = intval ($ page_size );
$ This-> total_size = intval ($ total_size );
If (! $ Current_page ){
$ This-> current_page = 1;
} Else {
$ This-> current_page = intval ($ current_page );
}
$ This-> total_pages = ceil ($ total_size/$ page_size );
$ This-> sub_pages = intval ($ sub_pages );
$ This-> pageparam = $ pageparam;
$ This-> pagelink = (empty ($ pagelink )? $ _ Server ["php_self"]: $ pagelink );
$ This-> static = $ static;
$ This-> page_tpl ['default'] = array ('tpl' =>'
{First} {prev} {liststart} {list} {listend} {next} {last} jump to the {jump} page
', 'Config' => array ());
}
Public function _ set ($ param, $ value ){
$ This-> $ param = $ value;
}
Public function _ get ($ param ){
Return $ this-> $ param;
}
/*
_ Destruct: a destructor called when the class is not in use. This function is used to release resources.
*/
Function _ destruct (){
Unset ($ page_size); // Number of Entries displayed on each page
Unset ($ total_size); // total number of items
Unset ($ current_page); // the currently selected page
Unset ($ sub_pages); // Number of pages displayed each time
Unset ($ total_pages); // total number of pages
Unset ($ page_tpl); // page template
Unset ($ pageparam); // page parameters, default page
Unset ($ pagelink );
Unset ($ static );
}
Private function urlparameters ($ url = array ()){
Foreach ($ url as $ key => $ val ){
If ($ key! = $ This-> pageparam)
$ Arg [] = $ key. '='. $ val;
}
$ Arg [] = $ this-> pageparam. '= *';
If ($ this-> static)
Return str_replace ('{page}', '*', $ this-> pagelink );
Else
Return $ this-> pagelink .'? '. Implode (' & ', $ arg );
}
Public function setpager ($ tpl_name = 'default', $ tpl = '', $ config = array ()){
If (empty ($ tpl ))
$ Tpl = $ this-> page_tpl ['default'] ['tpl'];
If (empty ($ config ))
$ Config = $ this-> page_tpl ['default'] ['config'];
$ This-> page_tpl [$ tpl_name] = array ('tpl' => $ tpl, 'config' => $ config );
}
Public function getpager ($ tpl_name = 'default '){
$ This-> getcurrentpage ();
Return $ this-> pager ($ this-> page_tpl [$ tpl_name]);
}
Public function getcurrentpage (){
$ This-> current_page = ($ _ get [$ this-> pageparam] <= intval ($ this-> total_pages )? ($ _ Get [$ this-> pageparam] <1? 1: $ _ get [$ this-> pageparam]): intval ($ this-> total_pages ));
}
Public function pager ($ page_tpl = ''){
If (empty ($ page_tpl ))
$ Page_tpl = $ this-> page_tpl ['default'];
$ Cfg = array ('recordcount' => intval ($ this-> total_size), 'pageindex' => intval ($ this-> current_page ), 'pagecount' => intval ($ this-> total_pages), 'pagesize' => intval ($ this-> page_size ), 'listlong' => intval ($ this-> sub_pages), 'listsidelong '=> 2, 'list' =>' * ', 'currentclass' => 'current ', 'link' => $ this-> urlparameters ($ _ get), 'First '=>' «', 'prev' => 'Shanghai '‹', 'next' => '›', 'last' => '»', 'more' => '... ', 'disabledclass' => 'disabled', 'jup' => 'input', 'jumpplus '=> '', 'jumpaction' => '', 'jumplong '=> 50 );
If (! Empty ($ page_tpl ['config']) {
Foreach ($ page_tpl ['config'] as $ key => $ val ){
If (array_key_exists ($ key, $ cfg ))
$ Cfg [$ key] = $ val;
}
}
$ Tmps tutorial tr = $ page_tpl ['tpl'];
$ Pstart = $ cfg ['pageindex']-($ cfg ['listlong']/2) + ($ cfg ['listlong'] % 2) + 1;
$ Pend = $ cfg ['pageindex'] + $ cfg ['listlong']/2;
If ($ pstart <1 ){
$ Pstart = 1;
$ Pend = $ cfg ['listlong'];
}
If ($ pend> $ cfg ['pagecount']) {
$ Pstart = $ cfg ['pagecount']-$ cfg ['listlong'] + 1;
$ Pend = $ cfg ['pagecount'];
}
If ($ pstart <1)
$ Pstart = 1;
For ($ I = $ pstart; $ I <= $ pend; $ I ++ ){
If ($ I = $ cfg ['pageindex'])
$ Plist. = ''. str_replace ('*', $ I, $ cfg ['list']).'';
Else
$ Plist. = ''. str_replace ('*', $ I, $ cfg ['list']).'';
}
If ($ cfg ['listsidelong ']> 0 ){
If ($ cfg ['listsidelong'] <$ pstart ){
For ($ I = 1; $ I <= $ cfg ['listsidelong ']; $ I ++ ){
$ Pliststart. = ''. str_replace ('*', $ I, $ cfg ['list']).'';
}
$ Pliststart. = ($ cfg ['listsidelong '] + 1) = $ pstart? '': $ Cfg ['more'].'';
} Else {
If ($ cfg ['listsidelong '] >=$ pstart & $ pstart> 1 ){
For ($ I = 1; $ I <= ($ pstart-1); $ I ++ ){
$ Pliststart. = ''. str_replace ('*', $ I, $ cfg ['list']).'';
}
}
}
If ($ cfg ['pagecount']-$ cfg ['listsidelong '])> $ pend ){
$ Plistend = ''. $ cfg ['more']. $ plistend;
For ($ I = ($ cfg ['pagecount']-$ cfg ['listsidelong ']) + 1); $ I <= $ cfg ['pagecount']; $ I ++ ){
$ Plistend. = ''. str_replace ('*', $ I, $ cfg ['list']).'';
}
} Else {
If ($ cfg ['pagecount']-$ cfg ['listsidelong ']) <= $ pend & $ pend <$ cfg ['pagecount']) {
For ($ I = ($ pend + 1); $ I <= $ cfg ['pagecount']; $ I ++ ){
$ Plistend. = ''. str_replace ('*', $ I, $ cfg ['list']).'';
}
}
}
}
If ($ cfg ['pageindex']> 1 ){
$ Pfirst = ''. $ cfg ['first'].'';
$ Pprev = ''. $ cfg ['prev'].'';
} Else {
$ Pfirst = ''. $ cfg ['first'].'';
$ Pprev = ''. $ cfg ['prev'].'';
}
If ($ cfg ['pageindex'] <$ cfg ['pagecount']) {
$ Plast = ''. $ cfg ['last'].'';
$ Pnext = ''. $ cfg ['Next'].'';
} Else {
$ Plast = ''. $ cfg ['last'].'';
$ Pnext = ''. $ cfg ['Next'].'';
}
Switch (strtolower ($ cfg ['Jump ']) {
Case 'input ':
$ Pjumpvalue = 'This. value ';
$ Pjump =' $ Pjump. = 'onkeydown = "webpage effect: if (event. charcode = 13 | event. keycode = 13) {if (! Isnan ('. $ pjumpvalue .')){';
$ Pjump. = ($ cfg ['jumpaction'] = ''? (Strtolower (substr ($ cfg ['link'], 0, 11) = 'javascript :')? Str_replace ('*', $ pjumpvalue, substr ($ cfg ['link'], 12): "document. location. href = '". str_replace ('*', '+ '. $ pjumpvalue. '+ '', $ cfg ['link']). ''; '): str_replace (" * ", $ pjumpvalue, $ cfg ['jumpaction']);
$ Pjump. = '} return false;} "/> ';
Break;
Case 'select ':
$ Pjumpvalue = "this. options [this. selectedindex]. value ";
$ Pjump =' $ Pjump. = '"title =" select the number of pages to jump to "> ';
If ($ cfg ['jumplong '] = 0 ){
For ($ I = 0; $ I <= $ cfg ['pagecount']; $ I ++ ){
$ Pjump. =' '. $ I .'';
}
} Else {
$ Pjumplong = intval ($ cfg ['jumplong ']/2 );
$ Pjumpstart = ($ cfg ['pageindex']-$ pjumplong) <1 )? 1: ($ cfg ['pageindex']-$ pjumplong ));
$ Pjumpstart = ($ cfg ['pagecount']-$ cfg ['pageindex']) <$ pjumplong )? ($ Pjumpstart-($ pjumplong-($ cfg ['pagecount']-$ cfg ['pageindex']) + 1): $ pjumpstart );
$ Pjumpstart = ($ pjumpstart <1 )? 1: $ pjumpstart );
$ J = 1;
For ($ I = $ pjumpstart; $ I <= $ cfg ['pageindex']; $ I ++, $ j ++ ){
$ Pjump. =' '. $ I .'';
}
$ Pjumplong = $ cfg ['pagecount']-$ cfg ['pageindex'] <$ pjumplong? $ Pjumplong: $ pjumplong + ($ pjumplong-$ j) + 1;
$ Pjumpend = $ cfg ['pageindex'] + $ pjumplong> $ cfg ['pagecount']? $ Cfg ['pagecount']: $ cfg ['pageindex'] + $ pjumplong;
For ($ I = $ cfg ['pageindex'] + 1; $ I <= $ pjumpend; $ I ++ ){
$ Pjump. =' '. $ I .'';
}
}
$ Pjump. ='';
Break;
}
$ Patterns = array ('/{recordcount}/', '/{pagecount}/', '/{pageindex}/', '/{pagesize }/', '/{list}/', '/{liststart}/', '/{listend}/', '/{first}/', '/{prev }/', '/{next}/', '/{last}/', '/{jump }/');
$ Replace = array ($ cfg ['recordcount'], $ cfg ['pagecount'], $ cfg ['pageindex'], $ cfg ['pagesize'], $ plist, $ pliststart, $ plistend, $ pfirst, $ pprev, $ pnext, $ plast, $ pjump );
$ Tmpstr = chr (13). chr (10). preg_replace ($ patterns, $ replace, $ tmpstr). chr (13). chr (10 );
Unset ($ cfg );
Return $ tmpstr;
}
}
?>
Http://www.bkjia.com/PHPjc/631735.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631735.htmlTechArticle? Php Tutorial/** template paging class, originated from easp tutorial database tutorial paging method, is easp paging php independent edition * support dynamic and static paging mode * easp official website http://easp.leng...