Copy code The code is as follows:
//Page function First page: url/1 Second page: url/2
function pages($url, $totalnum, $page, $pagesize = 20) {
$urladd = '';
$url .= '/';
$totalpage = ceil($totalnum / $pagesize);
if($totalpage < 2) return '';
$page = min($totalpage, $page);
$shownum = 5; // display How many pages* 2
$start = max(1, $page - $shownum);
$end = min($totalpage, $page + $shownum);
/ / If $shownum is insufficient, complete the left and right sides
$right = $page + $shownum - $totalpage;
$right > 0 && $start = max(1, $start -= $right);
$left = $page - $shownum;
$left < 0 && $end = min($totalpage, $end -= $left);
$s = '';
$page != 1 && $s .= '
◀';
if( $start > 1) $s .= '
1 '.($start > 2 ? '... ' : ' ').'';
for($i=$start; $i<=$end; $i++) {
if($i == $page) {
$ s .= '
'.$i.'';// checked
} else {
$s .= '
'.$i.'';
}
}
if($end != $totalpage) $s .= '
'.($totalpage - $end > 1 ? '... ' : '').$totalpage.'';
$page != $totalpage && $s .= '
▶';
return $s;
}
function mid($n, $min , $max) {
if($n < $min) return $min;
if($n > $max) return $max;
return $n;
}
function page($page, $n, $pagesize) {
$total = ceil($n / $pagesize);
$total < 1 AND $total = 1;
return mid($page, 1, $total);
}
We can handle the back-end part in just a few sentences.
Copy code The code is as follows:
$pagesize = 20; //How many users are displayed on each page
$n = user_count(); //Total number of users
$page = page($page, $n, $pagesize); //Current number of pages
$userlist = user_find($page, $pagesize); //Find Export the user
//html part of the current page, with paging effect, just render it directly to the page
$pagehtml = pages(url prefix, $n, $page, $pagesize);
http://www.bkjia.com/PHPjc/763012.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/763012.htmlTechArticleCopy code The code is as follows: //Pagination function First page: url/1 Second page: url/2 function pages($url, $totalnum, $page, $pagesize = 20) { $urladd = ''; $url .= '/'; $totalpage = ceil($t...