求一个可移植性强一点的分页程序!!!!!!!!!!!!
时间:2007-02-17 来源:PHP爱好者
function multi($num, $perpage, $curr_page, $mpurl) {
$multipage = '';
if($num > $perpage) {
$page = 10;
$offset = 2;
$pages = ceil($num / $perpage);
$from = $curr_page - $offset;
$to = $curr_page $page - $offset - 1;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
if($from <1) {
$to = $curr_page 1 - $from;
$from = 1;
if(($to - $from) <$page && ($to - $from) <$pages) {
$to = $page;
}
} elseif($to > $pages) {
$from = $curr_page - $pages $to;
$to = $pages;
if(($to - $from) <$page && ($to - $from) <$pages) {
$from = $pages - $page 1;
}
}
}
$multipage .= "<a href=../../"$mpurl&page=1"><<</a> ";
for($i = $from; $i <= $to; $i ) {
if($i != $curr_page) {
$multipage .= "<a href=../../"$mpurl&page=$i">[$i]</a> ";
} else {
$multipage .= '<u><b>['.$i.']</b></u> ';
}
}
$multipage .= $pages > $page ? " ... <a href=../../"$mpurl&page=$pages"> [$pages] >></a>" : " <a href=../../"$mpurl&page=$pages">>></a>";
}
return $multipage;
}
php爱好者站 http://www.phpfans.net php基础|php进阶|php模板.
$multipage = '';
if($num > $perpage) {
$page = 10;
$offset = 2;
$pages = ceil($num / $perpage);
$from = $curr_page - $offset;
$to = $curr_page $page - $offset - 1;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
if($from <1) {
$to = $curr_page 1 - $from;
$from = 1;
if(($to - $from) <$page && ($to - $from) <$pages) {
$to = $page;
}
} elseif($to > $pages) {
$from = $curr_page - $pages $to;
$to = $pages;
if(($to - $from) <$page && ($to - $from) <$pages) {
$from = $pages - $page 1;
}
}
}
$multipage .= "<a href=../../"$mpurl&page=1"><<</a> ";
for($i = $from; $i <= $to; $i ) {
if($i != $curr_page) {
$multipage .= "<a href=../../"$mpurl&page=$i">[$i]</a> ";
} else {
$multipage .= '<u><b>['.$i.']</b></u> ';
}
}
$multipage .= $pages > $page ? " ... <a href=../../"$mpurl&page=$pages"> [$pages] >></a>" : " <a href=../../"$mpurl&page=$pages">>></a>";
}
return $multipage;
}
php爱好者站 http://www.phpfans.net php基础|php进阶|php模板.
相关阅读 更多 +