PHP paging code call: $start=show_page($query,$page,$link,$offset); where: $start is the starting record, $query is the full record retrieval SQL statement, $page is the current page number, $link is the passed The page parameter $offset is the number of records displayed on each page
- //======function.php======
- //======Paging function=== =======
- function show_page($query,$page,$link,$offset)
- {
- $db = new mysql();
- $result = $db->query($query);
- $Page_size = $offset; //Get the maximum number of orders displayed on each page
- $count = $db->affected_rows($result); //Total number of orders
- $page_count = ceil($count/$Page_size); / /Calculate the total number of pages
-
- $init=1;
- $page_len=7;
- $max_p=$page_count;
- $pages=$page_count;
-
- //Judge the current page number
- $page=(empty($page )||$page<0)?1:$page;
- $start=$Page_size*($page-1);
- //Paging function code
- $page_len = ($page_len%2)?$page_len:$ pagelen+1; //The number of page numbers
- $pageoffset = ($page_len-1)/2; //The left and right offset of the number of page numbers
- $key="$count in total";
- $key.="$ page/$pages "; //What page, how many pages in total
- if($page!=1){
- $key.="First page "; //First page
- $key.="Previous page"; //Previous page
- }
- else
- {
- $key.="First page";//First Page
- $key.="Previous page"; //Previous page
- }
- if($pages>$page_len)
- {
- //If the current page is less than or equal to the left offset
- if($page<=$pageoffset ){
- $init=1;
- $max_p = $page_len;
- }
- else //If the current page is greater than the left offset
- {
- //If the right offset of the current page number exceeds the maximum number of pages
- if($page+$ pageoffset>=$pages+1){
- $init = $pages-$page_len+1;
- }
- else
- {
- //Calculation when both left and right offsets exist
- $init = $page-$pageoffset;
- $ max_p = $page+$pageoffset;
- }
- }
- }
- for($i=$init;$i<=$max_p;$i++)
- {
- if($i==$page){$key.=' ['.$i.']';}
- else {$key.=" ";}
- }
- if($page!=$pages)
- {
- $key.=" Next page ";//Next page
- $key.="Last page"; //Last page
- }
- else
- {
- $key.= "Next page"; //Next page
- $key.="Last page"; //Last page
- }
- echo "$key
";
- return $start;
- }
- ?>
Copy code
Call example
[code]
|