php分頁函數
Code
//分页
/*
$num 總條數
$perpage 每頁條數
$curpage 當前頁數
$mpurl 當前鏈接地址
*/
function multi($num, $perpage, $curpage, $mpurl) {
$page = 5; //當前顯示鏈接數
$multipage = '';
$mpurl .= strpos($mpurl, '?') ? '&' : '?';
$realpages = 1;
if($num > $perpage) {
$offset = 2;
$realpages = @ceil($num / $perpage);
$pages=$realpages;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
$from = $curpage - $offset;
$to = $from + $page - 1;
if($from < 1) {
$to = $curpage + 1 - $from;
$from = 1;
if($to - $from < $page) {
$to = $page;
}
} elseif($to > $pages) {
$from = $pages - $page + 1;
$to = $pages;
}
}
$multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.$mpurl.'page=1" class="first">1 </a>' : '').
($curpage > 1 ? '<a href="'.$mpurl.'page='.($curpage - 1).'" class="prev">‹‹</a>' : '');
for($i = $from; $i <= $to; $i++) {
$multipage .= $i == $curpage ? '<strong>'.$i.'</strong>' :
'<a href="'.$mpurl.'page='.$i.'">'.$i.'</a>';
}
$multipage .= ($curpage < $pages ? '<a href="'.$mpurl.'page='.($curpage + 1).'" class="next">››</a>' : '').
($to < $pages ? '<a href="'.$mpurl.'page='.$pages.'" class="last"> '.$realpages.'</a>' : '');
$multipage = $multipage ? '<div class="pages">'.'<em> '.$num.' </em>'.$multipage.'</div>' : '';
}
$maxpage = $realpages;
return $multipage;
}
//分页
/*
$num 總條數
$perpage 每頁條數
$curpage 當前頁數
$mpurl 當前鏈接地址
*/
function multi($num, $perpage, $curpage, $mpurl) {
$page = 5; //當前顯示鏈接數
$multipage = '';
$mpurl .= strpos($mpurl, '?') ? '&' : '?';
$realpages = 1;
if($num > $perpage) {
$offset = 2;
$realpages = @ceil($num / $perpage);
$pages=$realpages;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
$from = $curpage - $offset;
$to = $from + $page - 1;
if($from < 1) {
$to = $curpage + 1 - $from;
$from = 1;
if($to - $from < $page) {
$to = $page;
}
} elseif($to > $pages) {
$from = $pages - $page + 1;
$to = $pages;
}
}
$multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.$mpurl.'page=1" class="first">1 </a>' : '').
($curpage > 1 ? '<a href="'.$mpurl.'page='.($curpage - 1).'" class="prev">‹‹</a>' : '');
for($i = $from; $i <= $to; $i++) {
$multipage .= $i == $curpage ? '<strong>'.$i.'</strong>' :
'<a href="'.$mpurl.'page='.$i.'">'.$i.'</a>';
}
$multipage .= ($curpage < $pages ? '<a href="'.$mpurl.'page='.($curpage + 1).'" class="next">››</a>' : '').
($to < $pages ? '<a href="'.$mpurl.'page='.$pages.'" class="last"> '.$realpages.'</a>' : '');
$multipage = $multipage ? '<div class="pages">'.'<em> '.$num.' </em>'.$multipage.'</div>' : '';
}
$maxpage = $realpages;
return $multipage;
}