PHP paging class & lt ;? Php/*** paging class ** @ authorxiaojiong & amp; 290747680@qq.com * @ date2011-08-17 ** show (2) 1 .. 6263646 PHP paging class
Total_rows = $ data ['total _ rows ']; $ this-> parameter =! Empty ($ data ['parameter '])? $ Data ['parameter ']: ''; $ this-> list_rows =! Empty ($ data ['list _ rows ']) & $ data ['list _ rows'] <= 100? $ Data ['list _ rows ']: 15; $ this-> total_pages = ceil ($ this-> total_rows/$ this-> list_rows); $ this-> page_name =! Empty ($ data ['page _ name'])? $ Data ['page _ name']: 'P'; $ this-> ajax_func_name =! Empty ($ data ['Ajax _ func_name '])? $ Data ['Ajax _ func_name ']: ''; $ this-> method =! Empty ($ data ['method'])? $ Data ['method']: '';/* Current page */if (! Empty ($ data ['Now _ page']) {$ this-> now_page = intval ($ data ['Now _ page']);} else {$ this-> now_page =! Empty ($ _ GET [$ this-> page_name])? Intval ($ _ GET [$ this-> page_name]): 1 ;}$ this-> now_page = $ this-> now_page <= 0? 1: $ this-> now_page; if (! Empty ($ this-> total_pages) & $ this-> now_page> $ this-> total_pages) {$ this-> now_page = $ this-> total_pages ;} $ this-> first_row = $ this-> list_rows * ($ this-> now_page-1 );} /*** get the current connection * @ param $ page * @ param $ text * @ return string */protected function _ get_link ($ page, $ text) {switch ($ this-> method) {case 'Ajax ': $ parameter = ''; if ($ this-> parameter) {$ parameter = ','. $ this-> parameter;} return 'Ajax _ func_name. '(\''. $ Page. '\''. $ parameter. ') "href =" javascript: void (0) "> '. $ text. ''. "\ n"; break; case 'html': $ url = str_replace ('? ', $ Page, $ this-> parameter); return ''. $ text. ''. "\ n"; break; default: return '_ get_url ($ page ). '"> '. $ text. ''. "\ n"; break;}/*** sets the current page link */protected function _ set_url () {$ url = $ _ SERVER ['request _ URI ']. (strpos ($ _ SERVER ['request _ URI '],'? ')? '':"? "). $ This-> parameter; $ parse = parse_url ($ url); if (isset ($ parse ['query']) {parse_str ($ parse ['query'], $ params); unset ($ params [$ this-> page_name]); $ url = $ parse ['path']. '? '. Http_build_query ($ params);} if (! Empty ($ params) {$ url. = '&';} $ this-> url = $ url ;} /*** get the url of $ page * @ param $ page * @ return string */protected function _ get_url ($ page) {if ($ this-> url = NULL) {$ this-> _ set_url ();} // $ lable = strpos ('&', $ this-> url) ===false? '': '&'; Return $ this-> url. $ this-> page_name. '= '. $ page;}/*** get the first page * @ return string */public function first_page ($ name = 'first page') {if ($ this-> now_page> 5) {return $ this-> _ get_link ('1', $ name);} return '';} /*** last page ** @ param $ name * @ return string */public function last_page ($ name = 'Last page ') {if ($ this-> now_page <$ this-> total_pages-5) {return $ this-> _ get_link ($ this-> total_pages, $ Name);} return '';}/*** previous page * @ return string */public function up_page ($ name = 'previous page ') {if ($ this-> now_page! = 1) {return $ this-> _ get_link ($ this-> now_page-1, $ name);} return '';} /*** Next Page ** @ return string */public function down_page ($ name = 'next page ') {if ($ this-> now_page <$ this-> total_pages) {return $ this-> _ get_link ($ this-> now_page + 1, $ name);} return '';} /*** paging style output * @ param $ param * @ return string */public function show ($ param = 1) {if ($ this-> total_rows <1) {return '';} $ className = 'sho W _'. $ param; $ classNames = get_class_methods ($ this); if (in_array ($ className, $ classNames) {return $ this-> $ className ();} return '';} protected function show_2 () {if ($ this-> total_pages! = 1) {$ return = ''; $ return. = $ this-> up_page ('<'); for ($ I = 1; $ I <= $ this-> total_pages; $ I ++) {if ($ I ==$ this-> now_page) {$ return. = "$ I \ n";} else {if ($ this-> now_page-$ I >=4 & $ I! = 1) {$ return. = "... \ n "; $ I = $ this-> now_page-3;} else {if ($ I >=$ this-> now_page + 5 & $ I! = $ This-> total_pages) {$ return. = "... \ n "; $ I = $ this-> total_pages;} $ return. = $ this-> _ get_link ($ I, $ I ). "\ n" ;}}$ return. = $ this-> down_page ('>'); return $ return ;}} protected function show_1 () {$ plus = $ this-> plus; if ($ plus + $ this-> now_page> $ this-> total_pages) {$ begin = $ this-> total_pages-$ plus * 2 ;} else {$ begin = $ this-> now_page-$ plus;} $ begin = ($ begin> = 1 )? $ Begin: 1; $ return = ''; $ return. = $ this-> first_page (); $ return. = $ this-> up_page (); for ($ I = $ begin; $ I <= $ begin + $ plus * 2; $ I ++) {if ($ I >$ this-> total_pages) {break;} if ($ I ==$ this-> now_page) {$ return. = "$ I \ n";} else {$ return. = $ this-> _ get_link ($ I, $ I ). "\ n" ;}}$ return. = $ this-> down_page (); $ return. = $ this-> last_page (); return $ return;} protected function show_3 () {$ plus = $ th Is-> plus; if ($ plus + $ this-> now_page> $ this-> total_pages) {$ begin = $ this-> total_pages-$ plus * 2 ;} else {$ begin = $ this-> now_page-$ plus;} $ begin = ($ begin> = 1 )? $ Begin: 1; $ return = 'total '. $ this-> total_rows. 'records are classified '. $ this-> total_pages. 'page, current '. $ this-> now_page. 'Page'; $ return. = ', each page'; $ return. =''; $ Return. = $ this-> first_page (). "\ n"; $ return. = $ this-> up_page (). "\ n"; $ return. = $ this-> down_page (). "\ n"; $ return. = $ this-> last_page (). "\ n"; $ return. =''; For ($ I = $ begin; $ I <= $ begin + 10; $ I ++) {if ($ I> $ this-> total_pages) {break ;} if ($ I ==$ this-> now_page) {$ return. =''. $ I .'';} Else {$ return. =''. $ I .''; }}$ Return. =''; Return $ return ;}}
?
### Handle html static page paging ### set the method processing environment to html # set parameter to the static page parameter xxx.com/20-0-0-0-40 -?. Html note question mark #? The question mark position is automatically replaced by the destination page number # now_page current page (the static page cannot get the current page, so you only need to input it) $ params = array ('total _ rows '=> 100, # (required) 'method' => 'html', # (required) 'parameter '=> 'XXX. com/20-0-0-0-40 -?. Html ', # (required) 'Now _ page' => $ _ GET ['P'], # (required) 'list _ rows' => 10, # (optional) the default value is 15); $ page = new Core_Lib_Page ($ params); echo $ page-> show (1 ); #2 ### handle ajax pagination #### set the method processing environment to ajax # ajax_func_name javascript method for ajax pagination page navigation # The parameters attached to parameter ajax_func_name are empty by default # now_page does not reach the current page, so you only need to input $ params = array ('total _ rows '=> 100, 'method' => 'Ajax ', 'Ajax _ func_name' => 'gopage', 'Now _ page' => 1, # 'parameter '=> "'jiong ', 'username' ",); $ page = new Core_Lib_Page ($ params); echo $ page-> show (1); #7 # Added parameter6