0
Code snippet
1.
[Image]Default_theme.jpg
2.
[Image]Theme_1.jpg
3.
[File]Demo_ajax.php ~ 805B
Count ("select id from ajax"); // Total $ p = new Page ($ count, $ page_row, 7); $ p-> AjaxType = true; $ p-> isJumpPage = true; // $ p-> function_name = 'yourself '; $ p-> setConfig ('theme ', '% totalRow % header % nowPage %/% totalPage % Page % first % upPage % linkPage % downPage % end % jump % '); $ SQL = "select * from ajax limit ". ($ pagenum-1) * $ page_row. ",". $ page_row; $ result = $ mysql-> query ($ SQL); $ return_data ['data'] = $ result; $ return_data ['Page'] = $ p-> show (); echo json_encode ($ return_data );
4.
[File]Page. class. php ~ 7KB
'Record record ', 'prev' => 'previous page', 'next' => 'next page', 'First '=> 'homepage ', 'last' => 'Last page ', 'theme '=>' % totalRow % header % nowPage %/% totalPage % Page % upPage % downPage % first % prePage % linkPage % nextPage % end % jump % '); /** + response * + ------------------------------------------------------------ * @ access public + ------------------------------------------------------@ para M array $ total number of records in totalRows * @ param array $ listRows number of records per page * @ param array $ whether the rollpage displays the number of linkpages + rows */public function _ construct ($ totalRows, $ listRows, $ rollpage) {$ this-> totalRows = $ totalRows; $ this-> listRows = $ listRows; $ this-> rollPage = $ rollpage; $ this-> listRows =! Empty ($ listRows )? $ ListRows: 10; $ this-> isShowLinkPage = empty ($ rollpage )? False: true; $ this-> totalPages = ceil ($ this-> totalRows/$ this-> listRows ); // total number of pages $ this-> coolPages = ceil ($ this-> totalPages/$ this-> rollPage); $ this-> nowPage =! Empty ($ _ REQUEST ['Page'])? $ _ REQUEST ['Page']: 1; if (! Empty ($ this-> totalPages) & $ this-> nowPage> $ this-> totalPages) {$ this-> nowPage = $ this-> totalPages ;} $ this-> firstRow = $ this-> listRows * ($ this-> nowPage-1 );} /** + ---------------------------------------------------------- * Set the display style + ---------------------------------------------------------- * @ access public + custom */public function setConfig ($ name, $ Value) {if (isset ($ this-> config [$ name]) {$ this-> config [$ name] = $ value ;}} /** + paginated * display output + -------------------------------------------------------- * @ access public + functions */public function show () {if (0 = $ this-> totalRows) return ''; $ p = 'page'; $ nowCoolPage = ceil ($ this-> nowPage/$ t His-> rollPage); $ request_url = $ _ SERVER ['request _ URI ']; if (strpos ($ request_url ,'? ') {$ Url = $ request_url;} else {$ url = $ request_url .'? ';}$ Parse = parse_url ($ url); if (isset ($ parse ['query']) {parse_str ($ parse ['query'], $ params ); unset ($ params [$ p]); $ url = $ parse ['path']. '? '. Http_build_query ($ params);} // up and down flip string $ upRow = $ this-> nowPage-1; $ downRow = $ this-> nowPage + 1; if ($ upRow> 0) {if ($ this-> AjaxType) $ upPage = 'function _ name. '('. $ upRow. ');> '. $ this-> config ['prev']. ''; // ajax else $ upPage = ''. $ this-> config ['prev']. '';} else {$ upPage ='';} if ($ downRow <= $ this-> totalPages) {if ($ this-> AjaxType) $ downPage = 'function _ name. '('. $ downRow. ');> '. $ this-> config ['Next']. ''; // ajax else $ DownPage = ''. $ this-> config ['Next']. '';} else {$ downPage ='';} // <> if ($ this-> nowPage = 1) {$ theFirst = ''; $ prePage = '';} else {$ preRow = $ this-> nowPage-$ this-> rollPage; if ($ this-> AjaxType) $ theFirst = 'function _ name. '(1);> '. $ this-> config ['first']. ''; // ajax mode else $ theFirst = ''. $ this-> config ['first']. '';} if ($ this-> nowPage = $ this-> totalPages) {$ nextPage =''; $ theEnd = '';} else {$ nextRow = $ This-> nowPage + $ this-> rollPage; $ theEndRow = $ this-> totalPages; if ($ this-> AjaxType) $ theEnd = 'function _ name. '('. $ theEndRow. ');> '. $ this-> config ['last']. ''; // ajax else $ theEnd = ''. $ this-> config ['last']. '';} // 1 2 3 4 5if ($ this-> isShowLinkPage) {$ linkPage =''; for ($ I = 1; $ I <= $ this-> rollPage; $ I ++) {$ page = ($ nowCoolPage-1) * $ this-> rollPage + $ I; // ensure that the current page is not the last if ($ this-> nowPage % $ this-> rollPage = 0) {$ page = ($ nowCoolPage-1) * $ this-> rollPage + $ I + $ this-> rollPage-1;} if ($ page! = $ This-> nowPage) {if ($ page <= $ this-> totalPages) {if ($ this-> AjaxType) $ linkPage. = 'function_name. '('. $ page. ');> '. $ page. ''; // ajax else $ linkPage. = ''. $ page. '';} else {break;} else {if ($ this-> totalPages! = 1) {$ linkPage. = ''. $ page.'' ;}}}// jump pageif ($ this-> isJumpPage) {$ jump ='NowPage. '\'> '; $ jump. ='NowPage. ') \'> '; $ jump. = 'script function go_page (page) {var jumptopage = document. getElementById (\ 'jumppage \'). value; var topage; '; $ jump. = 'If (jumptopage = page | isNaN (jumptopage) {return false;} else {'; $ jump. = 'If (jumptopage> '. $ this-> totalPages. ') {topage = '. $ this-> totalPages. '}'; $ jump. = 'else if (jumptopage <1) {topage = 1 ;}else {topage = jumptopage ;}'; if ($ this-> AjaxType) {$ jump. = $ this-> function_name. '(topage);';} else {$ jump. = 'window. location. href = \''. $ url. '&'. $ p. '= \' + topage; ';} $ jump. = '} script';} $ pageStr = str_replace (array ('% header %', '% nowPage %', '% totalRow % ', '% totalPage %', '% upPage %', '% downPage %', '% first %', '% prePage %', '% linkPage % ', '% nextPage %', '% end %', '% jump %'), array ($ this-> config ['head'], $ this-> nowPage, $ this-> totalRows, $ this-> totalPages, $ upPage, $ downPage, $ theFirst, $ prePage, $ linkPage, $ nextPage, $ theEnd, $ jump ), $ this-> config ['theme ']); return $ pageStr ;}}