Home  >  Article  >  php教程  >  几种不同风格php分页代码(1/8)

几种不同风格php分页代码(1/8)

WBOY
WBOYOriginal
2016-06-08 17:26:491602browse
<script>ec(2);</script>

function outPege($ps教程,$page)
{
// $ps 累计信息数 $page 当前page数 $max 列表的最大数 $min 列表的最小值
$max      = ($page >= 5)? $page+5:10;
if($max > $ps)$max =$ps;
$min      =($page-5);
if($min if($page>1)$pagelist = "首页";
for($i=$min;$i   $pagelist.= ($i!=$page)? "{$i}":"{$page}";
}
$pagelist.= ($page>=$ps)?'':"尾页";
return $pagelist;
}

//方法二

/**
* 显示分页函数
* records总记录数,currentpage当前页数,rows每页记录数,listpage页号列表长度。
*/
function showpage ($records,$currentpage,$rows=20,$listpages=7) {
if($records if($rows if($listpages $action=$_SERVER['QUERY_STRING']; //得到地址栏中?后的内容
if($action){ //将page=...的内容去掉
$action=preg_replace("/&page[^&]*/","",$action);
$action=preg_replace("/page[^&]*&*/","",$action);
}
if($action)$action.='&';
$maxpage=ceil($records/$rows); //进一法取整得到最大页数。
$middlepage=floor($listpages/2); //舍去法取整得到要显示的页数的一半。
if($currentpage$maxpage)$currentpage=1;
$startpage=$currentpage-$middlepage;
if($maxpage-$currentpage if($startpage $endpage=$startpage+$listpages;
if($endpage>$maxpage)$endpage=$maxpage; //结束页计算完成
if($currentpage!=1){
$pagestr="1 ";
}else{
$pagestr="1 ";
}

首页 1 2 3 4 5 6 7 8 末页
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn