您的位置:首页 > 编程语言 > PHP开发

php文章页码的分页显示 函数 类似于Google搜索下面的分页

2010-05-16 22:56 633 查看
/**

页码分页显示,每页显示的页码随当前页面的页码而确定

* @param Int $totalnum 页码总数

* @param Int $perdisplay 要显示的页码数

* @return string $display 返回显示的页面代码

*/

function pagedisplay($totalnum,$perdisplay)

{

$cur=$_GET['curnum']?$_GET['curnum']:1;//$cur当前单击的页码

$shownum=min($totalnum,$perdisplay);//要显示的页码

$first=max(1,$cur-floor($shownum/2));//显示的第一项

$last=(($first+$shownum)<=$totalnum)?($first+$shownum-1):$totalnum;//显示的最后一项

$first=($perdisplay-1<=$totalnum-$first)?$first:($totalnum-$perdisplay+1>0?
$totalnum-$perdisplay+1:1
);

//确保每个页面显示$shownum个页码

for($i=$first;$i<=$last;$i++)

{$display.= $i==$cur?$i:"<a style='border:1px solid #e3e3e3; padding:5px; ' href='".$_SERVER['PHP_SELF']."?curnum=$i"."'>$i</a>";

}

return $display;

}

echo pagedisplay(19,7);
//列子:共有19页,每次显示7个页码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: