Code of the PHP module for listing array elements by page in thinkphp: classNewsActionextendsAction {public $ page; page, current page functionNews () {$ listM (News)-& gt; field (id, title) -& gt; where (stat thinkphp displays array elements by page
PHP module code: class NewsAction extends Action {public $ page = ''; // page, current page number function News () {$ list = M (" News ") -> field ('Id, TITLE')-> where ("status = 5")-> findAll (); // pagination $ list = $ this-> array_page ($ list); // end $ num = 0; $ URL = "http://www.baidu.com/"; $ suffixName = '.html '; foreach ($ list as $ key => $ val) {$ num = $ key + 1; $ str. = ''. $ num. "). ". $ val ['title']."
";}$ Str = preg_replace ('/(. *), \ s $/', '\ 1', $ str); $ str. ="". $ This-> page ."
"; Return $ str ;} // array paging method/*** array $ array * integer $ showCount number of records per page * ------------------------------ * return array */function array_page ($ array, $ listRows = 12, $ showCount = 4) {$ p = C ('Var _ page'); $ url = $ _ SERVER ['request _ url']. "/". $ p. "/"; $ page =! Empty ($ _ GET [C ('Var _ page')])? $ _ GET [C ('Var _ page')]: 1; $ upRow = $ PAGE-1; $ downRow = $ page + 1; $ linkPage = ""; $ totalPage = (int) count ($ array); $ pagetotal = ceil ($ totalPage/$ listRows); // total page number if ($ page <= ceil ($ showCount) /2) {$ minpg = 1; $ maxpg = $ showCount + 1; if ($ maxpg >=$ pagetotal) $ maxpg = $ pagetotal + 1 ;} elseif ($ page> ceil ($ showCount)/2) & $ page <($ pagetotal-ceil ($ showCount/2 ))) {$ minpg = $ page-ceil ($ showCount)/2) + 1; $ maxpg = $ page + ceil ($ showCount)/2) + 1; if ($ maxpg >=$ pagetotal) $ maxpg =$ pagetotal;} elseif ($ page >=$ pagetotal-ceil ($ showCount)/2 )) {$ minpg = $ pagetotal-($ showCount-1); if ($ minpg = 1) $ minpg = 2; $ maxpg = $ pagetotal + 1;} $ linkPage. = "". $ totalPage. "Record ". $ page. "/". $ pagetotal. "page"; if ($ pagetotal = 1) {$ linkPage. = "1";} else {if ($ page> 1) {$ linkPage. = "first page"; $ linkPage. = "previous page" ;}for ($ I = $ minpg; $ I <$ maxpg; $ I ++) {if ($ page ==$ I) {$ linkPage. = "". $ I. "";} else {$ linkPage. = "$ I" ;}}if ($ page <$ pagetotal) {$ linkPage. = "next page"; $ linkPage. = "Last page"; }}if ($ listRows <$ totalPage) {if ($ page <= 1 | empty ($ page) {$ page = 0 ;} else {$ page = intval ($ page)-1 ;}$ array = array_slice ($ array, $ page * $ listRows, $ listRows, true );} $ this-> page = $ linkPage; if (1 = $ pagetotal) $ this-> page = ''; return $ array ;}} front-end Html code: