php 分页函数

在一个网站中,分布必不可少,如何巧妙的组织一个可控性强的分页函数显得犹为重要,前面在模型类中已经把它交给了函数multipage,这里,对它进行完善

function multipage($page, $page_num, $url, $isajax = 0) {
    
    $count = count($url);
    if ($isajax) {
        $css = " class='__ajax' action=\\".__page-box\\" ";
    } else {
        $css = '';
    }
    //html开始
    $html = '
    '; //构造上一页 if ($page == 1) { $html .= "
  • <
  • "; } //构造第一页 if ($page == 1) { $html .= "
  • 1
  • "; } else { $url[$count] = 1; $html .= "
  • 1
  • "; } //构造显示中间的页码 if (1) { $arr = range($page-1, $page + 2, 1); } else { $arr = range(2, 3, 1); $tmp1 = array_merge(range($page - 2, $page + 2, 1) , range($page_num - 2, $page_num + 1, 1)); $arr = array_unique(array_merge($arr, $tmpl)); } $j = 1; foreach ($arr as $i) { if ($page_num < $i || $i < 2) { continue; } if ($j > 0 and $i - $j > 1) { $html .= "
  • ...
  • "; } if ($page == $i) { $html .= "
  • $i
  • "; } else { $url[$count] = $i; $html .= "
  • $i
  • "; } $j = $i; } if ($page_num - $i > 1) { $html .= "
  • ...
  • "; $url[$count] = $page_num; $html .= "
  • $page_num
  • "; } elseif ($page_num - $i == 1) { $url[$count] = $page_num; $html .= "
  • $page_num
  • "; } if ($page == $page_num) { $html .= "
  • >
  • "; } else { $next = $page + 1; $url[$count] = $next; $html .= "
  • >
  • "; } $html .= "
"; echo $html; }

你可能感兴趣的:(php 分页函数)