With regard to the array paging function, the advantage of using Arrays for paging is that it is convenient to perform Combined Multi-table queries, you only need to put the query results in an array. The following is an array paging function. The page_array function is used for Array paging. The show_array function is used for paging function operation and display. It must be used in combination. two functions are linked by the global variable $ countpage. This variable is used to track the total number of page numbers.
<? PHP/*** array paging function core function array_slice * before using this function, you must first query all the data in the database in a certain order and store the data in the array * $ count how many entries per page data * $ Page Current page * $ all arrays queried by array * order 0-unchanged 1-Reverse Order */function page_array ($ count, $ page, $ array, $ order) {Global $ countpage; # set the global variable $ page = (empty ($ page ))? '1': $ page; # judge whether the current page is empty. If it is null, it indicates the first page $ start = ($ page-1) * $ count; # Calculate the start position of each page. If ($ order = 1) {$ array = array_reverse ($ array) ;}$ totals = count ($ array ); $ countpage = Ceil ($ totals/$ count); # calculate the total number of pages $ pagedata = array (); $ pagedata = array_slice ($ array, $ start, $ count ); return $ pagedata; # Return query data}/*** paging and display function ** $ countpage global variable, write ** $ URL current URL */function show_array ($ countpage, $ URL) {$ page = empty ($ _ Get ['page'])? 1: $ _ Get ['page']; if ($ page> 1) {$ uppage = $ page-1;} else {$ uppage = 1 ;} if ($ page <$ countpage) {$ nextpage = $ page + 1;} else {$ nextpage = $ countpage;} $ STR = '<Div style = "border: 1px; width: 300px; Height: 30px; color: # 9999cc "> '; $ Str. = "<span> total page {$ countpage}/Page {$ page} </span>"; $ Str. = "<span> <a href = '$ URL? Page = 1 '> homepage </a> </span> "; $ Str. =" <span> <a href =' $ URL? Page = {$ uppage} '> previous page </a> </span> "; $ Str. =" <span> <a href =' $ URL? Page = {$ nextpage} '> next page </a> </span> "; $ Str. =" <span> <a href =' $ URL? Page = {$ countpage} '> last page </a> </span> "; $ Str. =' </div> '; return $ STR ;}?>