php 分页函数multi() discuz
(编辑:jimmy 日期: 2024/11/19 浏览:3 次 )
复制代码 代码如下:
/*
* 分页函数
* $num 总条数,$perpage 一页多少条, $curpage 当前页, $mpurl url, $page = 10 显示几个分页
*
*/
function multi($num, $perpage, $curpage, $mpurl, $page = 10) {
$multipage = '';
$realpages = 1;
if ($num > $perpage){
$offset = 4;
$realpages = @ceil($num / $perpage);
if ($page > $realpages) {
$form = 1;
$to = $realpages;
}else {
$form = $curpage - $offset;
$to = $form + $page - 1;
if ($form < 1) {
$form = 1;
//$to = $curpage + 1 - $form;
if ($to - $form < $page) {
$to = $page;
}
}
}
$multipage = ($curpage > 1 ? '<a href="'.$mpurl.'page='.($curpage - 1).'">up</a> ' : '');
for ($i = $form; $i <= $to; $i++) {
$multipage .= $i == $curpage ? '<strong>'.$i.'</strong> ' :
'<a href="'.$mpurl.'page='.$i.'">'.$i.'</a> ';
}
$multipage .= $curpage < $realpages ? '<a href="'.$mpurl.'page='.($curpage + 1).'">next</a> ' : '';
$multipage = $multipage ? '<div class="pages">'.$multipage.'</div>' : '';
}
return $multipage;
}
/*
* 分页函数
* $num 总条数,$perpage 一页多少条, $curpage 当前页, $mpurl url, $page = 10 显示几个分页
*
*/
function multi($num, $perpage, $curpage, $mpurl, $page = 10) {
$multipage = '';
$realpages = 1;
if ($num > $perpage){
$offset = 4;
$realpages = @ceil($num / $perpage);
if ($page > $realpages) {
$form = 1;
$to = $realpages;
}else {
$form = $curpage - $offset;
$to = $form + $page - 1;
if ($form < 1) {
$form = 1;
//$to = $curpage + 1 - $form;
if ($to - $form < $page) {
$to = $page;
}
}
}
$multipage = ($curpage > 1 ? '<a href="'.$mpurl.'page='.($curpage - 1).'">up</a> ' : '');
for ($i = $form; $i <= $to; $i++) {
$multipage .= $i == $curpage ? '<strong>'.$i.'</strong> ' :
'<a href="'.$mpurl.'page='.$i.'">'.$i.'</a> ';
}
$multipage .= $curpage < $realpages ? '<a href="'.$mpurl.'page='.($curpage + 1).'">next</a> ' : '';
$multipage = $multipage ? '<div class="pages">'.$multipage.'</div>' : '';
}
return $multipage;
}
下一篇:一个php Mysql类 可以参考学习熟悉下