Effect Chart:
Remember before I saw a page number way of paging effect, the number of pages more folding lines continue to show up to more than 60 pages, hehe! A little influence beautiful!
So I wrote a page-numbering program that automatically adapts to the range.
In other words, the page number format follows
<< < 1 2 3 4 5 6 7 > >>
<< < 6 7 8 9 all > >>
Underline is the current page, so you can display a similar page number, to avoid too long affect the appearance of
Code added a note, mainly novice to see, oh, write this function, did not consider the separation of performance structure, the master will not be prosecuted!
<?php
Function page ($page, $total, $phpfile, $pagesize =10, $pagelen =7) {
$pagecode = ';//define variable to hold page-generated HTML
$page = Intval ($page);//Avoid Non-numeric page numbers
$total = Intval ($total);//Guaranteed Total record value type is correct
if (! $total) return array ();//The total number of records is zero returns an empty array
$pages = Ceil ($total/$pagesize);//Calculate Total page
Handling Page number legality
if ($page <1) $page = 1;
if ($page > $pages) $page = $pages;
Calculate query Offsets
$offset = $pagesize * ($page-1);
Page range Calculation
$init = 1;//starting page number
$max = $pages;//End page number
$pagelen = ($pagelen%2)? $pagelen: $pagelen +1;//page number
$pageoffset = ($pagelen-1)/2;//the left and right offset of page number
Generate HTML
$pagecode = ' <div class= ' page ' > ';
$pagecode. = "<span> $page/$pages </span>";//The first few pages, altogether several pages
If this is the first page, the connection to the first and previous pages is not displayed
if ($page!=1) {
$pagecode. = "<a href=\" {$phpfile}?page=1\ "><<</a>";//The first page
$pagecode. = "<a href=\" {$phpfile}?page=. ($page-1). " \ ><</a>/Previous page
}
Can be offset when the number of pages is greater than page numbers
if ($pages > $pagelen) {
If the current page is less than or equal to the left offset
if ($page <= $pageoffset) {
$init = 1;
$max = $pagelen;
}else{//If the current page is greater than the left offset
If the current page number right offset exceeds the maximum page count
if ($page + $pageoffset >= $pages + 1) {
$init = $pages-$pagelen +1;
}else{
Computation of the left and right offsets when they exist
$init = $page-$pageoffset;
$max = $page + $pageoffset;
}
}
}
Generate HTML
for ($i = $init; $i <= $max; $i + +) {
if ($i = = $page) {
$pagecode. = ' <span> '. $i. ' </span> ';
} else {
$pagecode. = "<a href=\" {$phpfile}?page={$i}\ "> $i </a>";
}
}
if ($page!= $pages) {
$pagecode. = "<a href=\" {$phpfile}?page=. ($page + 1). " \ ">></a>";//Next page
$pagecode. = "<a href=\" {$phpfile}?page={$pages}\ ">>></a>";//Last Page
}
$pagecode. = ' </div> ';
Return Array (' Pagecode ' => $pagecode, ' sqllimit ' => ' limit '. $offset ', '. $pagesize);
}
?>