On the array of paging function, the advantage of using an array for paging is convenient for the Union of multiple table query, just want to put the results of the query in the array can be the following is the function of the array paging, function Page_array for the array of pagination, function Show_array for the operation and display of the paging function, Need to be used in conjunction with. Two functions are linked by a global variable $countpage, which is used to track the total number of pages.
<?PHP/** Number of Components page function core function Array_slice * Before using this function, all the data in the database must be queried in a certain order to be stored in the array * $count how many data per page * $page Current page * $array Query out all arrays * Order 0-Unchanged 1-Reverse order*/ functionPage_array ($count,$page,$array,$order){ Global $countpage;#Set Global Variables $page=(Empty($page))?‘ 1 ':$page;#determines whether the current page is empty if it is empty, it is represented as the first page $start=($page-1) *$count;#calculate the starting 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} /** * pagination and display function * $countpage global variable, write * $url current URL*/ functionShow_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 {$countpage} page/Section {$page} page </span> "; $str. = "<span><a href="$url? page=1 ' > Home </a></span> "; $str. = "<span><a href="$url? page={$uppage} ' > previous page </a></span> '; $str. = "<span><a href="$url? page={$nextpage} ' > Next </a></span> '; $str. = "<span><a href="$url? page={$countpage} ' > Last </a></span> '; $str. = ' </div> '; return $str; } ?>
PHP array-based paging implementation