时间:2021-07-01 10:21:17 帮助过:20人阅读
$curpage = isset($_GET['curpage'])? $_GET['curpage'] : 1;
$total = 1000;
$pagesize = 20;
$url = 'page.php';
$show = 10;
echo page($curpage, $pagesize, $total, $url, $show);
function page($curpage, $pagesize, $total, $url, $show){
if($total<=0
------解决方案--------------------
$curpage<=0
------解决方案--------------------
$pagesize<=0
------解决方案--------------------
$show<=0){
return '';
}
$pagecount = (int)(($total-1)/$pagesize)+1;
if($curpage>$pagecount){
$curpage = $pagecount;
}
$tmp = '';
$step = (int)($show/2);
if($curpage-$step<=0){
$start = 1;
$end = $pagecount>$show? $show : $pagecount;
}elseif($curpage+$step>=$pagecount){
$start = $pagecount-$show+1;
$end = $pagecount;
}else{
$start = $curpage-$step;
$end = $start+$show-1;
}
if($curpage>1){
$tmp .= '上一页';
}
for($i=$start; $i<=$end; $i++){
if($i==$curpage){
$tmp .= ''.$i.'';
}else{
$tmp .= ''.$i.'';
}
}
if($curpage<$pagecount){
$tmp .= '下一页';
}
$tmp .= '总数:'.$total.',共'.$pagecount.'页';
return $tmp;
}
?>