首页 > 开发 > PHP > 正文

通用分页函数 split_page()

2024-05-04 22:58:55
字体:
来源:转载
供稿:网友

// 分页显示:[1]... [<<] - [<] [9] [10] [11] [12] [13] [14] [15] [16] [>] - [>>] ...[232]
// url format: ./list.php?page= ; system will add the pagenum after the url automaticly
// $id: split_page.php,v 1.1.1.1 2002/08/24 14:26:41 hightman exp $
 
function split_page($url, $total, $curpage = 1, $perpage = 15, $perlist = 8) {
    if ($total <= 0) return;
   
    if ($curpage <= 0) $curpage = 1;
    $totalpage = ceil($total / $perpage);
    $totallist = ceil($totalpage / $perlist);
   
    if ($curpage > $totalpage) $curpage = $totalpage;
    $curlist = ceil($curpage / $perlist);
   
    $toppage = $curlist * $perlist;
    if ($toppage > $totalpage) $toppage = $totalpage;
   
    $botpage = ($curlist - 1) * $perlist + 1;
    if ($botpage < 1) $botpage = 1;
   
    $ret = '';
   
    if ($curlist > 1) {
         $ret .= "<a title=/"第一页/" href=/"" . $url . "1/">[1]</a>.../n";
         $ret .= "<a title=/"上一列/" href=/"" . $url . ($botpage - $perlist)."/">[&lt;&lt;]</a> -/n";
    }
   
    if ($curpage > 1)
         $ret .= "<a title=/"上一页/" href=/"" . $url . ($curpage - 1) . "/">[&lt;]</a>/n";
   
    do {
         if ($botpage == $curpage)
             $ret .= "<b><font color=red>[" . $botpage . "]</font></b>/n";
        else
             $ret .= "<a title=/"第" . $botpage . "页/" href=/"" . $url . $botpage . "/">[" . $botpage . "]</a>/n";
    } while ($botpage++ < $toppage);
   
    if ($totalpage > $curpage)
            $ret .= "<a title=/"下一页/" href=/"" . $url . ($curpage + 1) . "/">[&gt;]</a>/n";
   
    if ($totallist > $curlist) {
            $ret .= "- <a title=/"下一列/" href=/"" . $url . ($toppage + 1) . "/">[&gt;&gt;]</a>/n";
            $ret .= "...<a title=/"最后一页/" href=/"" . $url . $totalpage . "/">[" . $totalpage . "]</a>/n";
    }
   
    $ret .= "total: " . $total;
    return ($ret);
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表