Pages in AJAX mode
Pages in AJAX mode
1000, 'perpage' => 20); echo 'MoDe: 1
'. $ Page-> show (); echo' mode: 2
'. $ Page-> show (2); echo 'MoDe: 3
'. $ Page-> show (3); echo 'MoDe: 4
'. $ Page-> show (4); echo 'start AJAX mode: '; $ ajaxpage = new page (array ('total' => 1000, 'perpage' => 20, 'Ajax '=> 'Ajax _ page', 'page _ name' => 'test'); echo 'MoDe: 1
'. $ Ajaxpage-> show (); */class minupage {/*** config, public */var $ page_name = "p"; // page tag, used to control url pages. For example, xxx. php? PB_pagevar $ next_page = '>' in PB_page = 2; // Next Page var $ pre_page = '<'; // Previous Page var $ first_page = 'first '; // homepage var $ last_page = 'Lala'; // var $ pre_bar = '<'; // The Last page var $ next_bar = '> '; // var $ format_left = '['; var $ format_right = ']'; var $ is_ajax = false; // whether the AJAX paging mode/*** private **/var $ pagebarnum = 10; // control the number of record entries. Var $ totalpage = 0; // total number of pages var $ ajax_action_name = ''; // AJAX action name var $ nowindex = 1; // var $ url = ""; // url address header var $ offset = 0;/*** constructor *** @ param array $ array ['total'], $ array ['perpage'], $ array ['nowindex '], $ array ['URL'], $ array ['Ajax']... */function minupage ($ array) {if (is_array ($ array) {if (! Array_key_exists ('total', $ array) $ this-> error (_ FUNCTION __, 'need a param of total '); $ total = intval ($ array ['total']); $ perpage = (array_key_exists ('perpage', $ array ))? Intval ($ array ['perpage']): 10; $ nowindex = (array_key_exists ('nowindex ', $ array ))? Intval ($ array ['nowindex ']): ''; $ url = (array_key_exists ('URL', $ array ))? $ Array ['URL']: '';} else {$ total = $ array; $ perpage = 10; $ nowindex =''; $ url = '';} if ((! Is_int ($ total) | ($ total <0) $ this-> error (_ FUNCTION __, $ total. 'is not a positive integer! '); If ((! Is_int ($ perpage) | ($ perpage <= 0) $ this-> error (_ FUNCTION __, $ perpage. 'is not a positive integer! '); If (! Empty ($ array ['page _ name']) $ this-> set ('page _ name', $ array ['page _ name']); // Set pagename $ this-> _ set_nowindex ($ nowindex); // set the current page $ this-> _ set_url ($ url ); // Set the link address $ this-> totalpage = ceil ($ total/$ perpage); $ this-> offset = ($ this-> nowindex-1) * $ perpage; if (! Empty ($ array ['Ajax ']) $ this-> open_ajax ($ array ['Ajax']); // open the AJAX mode}/*** to set the variable name value in the class. if the change volume does not belong to this class, throw an exception ** @ param string $ var * @ param string $ value */function set ($ var, $ value) {if (in_array ($ var, get_object_vars ($ this) $ this-> $ var = $ value; else {$ this-> error (_ FUNCTION __, $ var. "does not belong to PB_Page! ") ;}}/*** Open the inverted AJAX mode ** @ param string $ action: The default ajax-triggered action. */Function open_ajax ($ action) {$ this-> is_ajax = true; $ this-> ajax_action_name = $ action ;} /*** get the code for "next page" ** @ param string $ style * @ return string */function next_page ($ style = '') {if ($ this-> nowindex <$ this-> totalpage) {return $ this-> _ get_link ($ this-> _ get_url ($ this-> nowindex + 1 ), $ this-> next_page, $ style);} return ''. $ this-> next_page. '';}/*** get the code for displaying the previous page ** @ param string $ style * @ return string */function pre_page ($ Style = '') {if ($ this-> nowindex> 1) {return $ this-> _ get_link ($ this-> _ get_url ($ this-> nowindex-1 ), $ this-> pre_page, $ style);} return ''. $ this-> pre_page. '';}/*** get the code for displaying the" homepage "** @ return string */function first_page ($ style = '') {if ($ this-> nowindex = 1) {return ''. $ this-> first_page. '';} return $ this-> _ get_link ($ this-> _ get_url (1), $ this-> first_page, $ style );} /*** get the code for displaying the "last page" ** @ return string */function last_page ($ style = '') {If ($ this-> nowindex = $ this-> totalpage) {return ''. $ this-> last_page. '';} return $ this-> _ get_link ($ this-> _ get_url ($ this-> totalpage), $ this-> last_page, $ style );} function nowbar ($ style = '', $ nowindex_style ='') {$ plus = ceil ($ this-> pagebarnum/2 ); if ($ this-> pagebarnum-$ plus + $ this-> nowindex> $ this-> totalpage) $ plus = ($ this-> pagebarnum-$ this-> totalpage + $ this-> nowindex); $ begin = $ this-> nowindex-$ plus + 1; $ begin = ($ begi N> = 1 )? $ Begin: 1; $ return = ''; for ($ I = $ begin; $ I <$ begin + $ this-> pagebarnum; $ I ++) {if ($ I <= $ this-> totalpage) {if ($ I! = $ This-> nowindex) $ return. = $ this-> _ get_text ($ this-> _ get_link ($ this-> _ get_url ($ I), $ I, $ style); else $ return. = $ this-> _ get_text (''. $ I. '');} else {break;} $ return. = "\ n";} unset ($ begin); return $ return ;} /*** get the code for displaying the jump button ** @ return string */function select ($ url) {$ return =''; For ($ I = 1; $ I <= $ this-> totalpage; $ I ++) {if ($ I = $ this-> nowindex) {$ return. =''. $ I .'';} Else {$ return. =''. $ I .'';}} Unset ($ I); $ return. =''; Return $ return;}/*** obtain the value required by limit in the mysql statement ** @ return string */function offset () {return $ this-> offset ;} /*** control the paging display style (you can add the corresponding style) ** @ param int $ mode * @ return string */function show ($ mode = 1, $ url = '') {switch ($ mode) {case '1': $ this-> next_page = 'next page'; $ this-> pre_page = 'previous page '; return $ this-> pre_page (). $ this-> nowbar (). $ this-> next_page (). 'Di '. $ this-> select ($ url ). 'Page'; break; case '2': $ this-> next_page = 'next page'; $ th Is-> pre_page = 'previous page'; $ this-> first_page = 'homepage '; $ this-> last_page = 'Last page'; return $ this-> first_page (). $ this-> pre_page (). '[nth '. $ this-> nowindex. 'page] '. $ this-> next_page (). $ this-> last_page (). 'Di '. $ this-> select ($ url ). 'Page'; break; case '3': $ this-> next_page = 'next page'; $ this-> pre_page = 'previous page '; $ this-> first_page = 'homepage'; $ this-> last_page = 'tail'; return $ this-> first_page (). $ this-> pre_page (). $ this-> next_page (). $ this-> last_page (); Break; case '4': $ this-> next_page = 'next page'; $ this-> pre_page = 'previous page'; return $ this-> pre_page (). $ this-> nowbar (). $ this-> next_page (); break; case '5': return $ this-> pre_bar (). $ this-> pre_page (). $ this-> nowbar (). $ this-> next_page (). $ this-> next_bar (); break;}/* ---------------- private function (private method) restart * // *** sets the url header address * @ param: string $ url * @ return boole An */function _ set_url ($ url = "") {if (! Empty ($ url) {// manually set $ this-> url = $ url. (stristr ($ url ,'? '))? '&':'? '). $ This-> page_name. "=";} else {// automatically obtain if (empty ($ _ SERVER ['query _ string']) {// If QUERY_STRING does not exist, $ this-> url = $ _ SERVER ['request _ URI ']. "? ". $ This-> page_name. "=";} else {// if (stristr ($ _ SERVER ['query _ string'], $ this-> page_name. '=') {// the url contains the page parameter $ this-> url = str_replace ($ this-> page_name. '= '. $ this-> nowindex, '', $ _ SERVER ['request _ URI ']); $ last = $ this-> url [strlen ($ this-> url) -1]; if ($ last = '? '| $ Last =' & ') {$ this-> url. = $ this-> page_name. "=";} else {$ this-> url. = '&'. $ this-> page_name. "=" ;}} else {// $ this-> url = $ _ SERVER ['request _ URI ']. '&'. $ this-> page_name. '=';} // end if}/*** sets the current page **/function _ set_nowindex ($ nowindex) {if (empty ($ nowindex) {// The system obtains if (isset ($ _ GET [$ this-> page_name]). {$ this-> nowindex = intval ($ _ GET [$ this-> page_name]) ;}} else {// manually set $ this-> nowindex = intval ($ now Index) ;}}/*** returns the address value for the specified page ** @ param int $ pageno * @ return string $ url */function _ get_url ($ pageno = 1) {return $ this-> url. $ pageno;}/*** get the pagination display text. for example, by default, _ get_text ('1 ') [1] ** @ param String $ str * @ return string $ url */function _ get_text ($ str) {return $ this-> format_left. $ str. $ this-> format_right;}/*** get link address */function _ get_link ($ url, $ text, $ style = '') {$ style = (empty ($ style ))? '': 'Class = "'. $ style. '"'; if ($ this-> is_ajax) {// if the AJAX mode is used, return 'Ajax _ action_name. '(\''. $ url. '\') "> '. $ text. '';} else {return ''. $ text. '';}/*** error handling method */function Error ($ function, $ errormsg) {die ('error in file'. _ FILE __.', Function'. $ Function .'(): '. $ Errormsg) ;}}?>
The above is the content. For more information, please follow the PHP Chinese network (www.php1.cn )!