常用php分页函数…
/**
*函数print_paging
*功能:实现分页
*将分页的导航制作包装成一个表的格式
*分页导航格式,例如如下格式:
*/
//
几页/几条 | 首页 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 尾页 |
function print_paging($tb) {
$this->table = $tb;
$page_id = $this->get_page_id ();
$up_page = $this->get_up_page ( $page_id );
$ne_page = $this->get_next_page ( $page_id );
$total_rows = $this->counting ();
$total_pages = $this->get_total_pages ();
$page_size = $this->page_size;
if ($page_size >= $total_rows) {
//当每页的最大条数大于查询的总条数时,即只有1页
} else {
if ($total_pages <= 7) { //当页码数小于等于7页时,打印出所有的页码链接,格式如:共34条/7页 首页 1 2 3 4 5 6 7 尾页
$str = "
共" . $total_rows . "条/" . $total_pages . "页 | " . $this->print_url ( "首页", 1 ) . " |
for($i = 1; $i <= $total_pages; $i ++) {
if ($i == $page_id) {
$str .= "
" . $i . "";} else {
$str .= "
" . $this->print_url ( $i, $i ) . "";}
}
$str .= "
" . $this->print_url ( "尾页", $total_pages ) . "";//return $str;
} else { //当页面数大于7时,打印当前页的前三页后后三页,格式如下:共34条/12页 首页 3 4 5 6 7 8 9 尾页
if ($page_id <= 3) { //当页码数小于3时,打印当前页以及前面的所有页和随后的3页
$str = "
共" . $total_rows . "条/" . $total_pages . "页 | " . $this->print_url ( "首页", 1 ) . " |
for($i = 1; $i <= $page_id + 3; $i ++) {
if ($i == $page_id) {
$str .= "
" . $i . "";} else {
$str .= "
" . $this->print_url ( $i, $i ) . "";}
}
$str .= "
" . $this->print_url ( "尾页", $total_pages ) . "";//return $str;
}
if ($page_id >= $total_pages - 3) { //当页码数小于总页数-3时,打印当前页前三页和最后的所有页
$str = "
共" . $total_rows . "条/" . $total_pages . "页 | " . $this->print_url ( "首页", 1 ) . " |
for($i = $page_id - 3; $i <= $total_pages; $i ++) {
if ($i == $page_id) {
$str .= "
" . $i . "";} else {
$str .= "
" . $this->print_url ( $i, $i ) . "";}
}
$str .= "
" . $this->print_url ( "尾页", $total_pages ) . "";//return $str;
}
if ($page_id < $total_pages - 3 && $page_id > 3) { //打印前三页当前页和后三页
$str = "
共" . $total_rows . "条/" . $total_pages . "页 | " . $this->print_url ( "首页", 1 ) . " |
for($i = $page_id - 3; $i <= $page_id + 3; $i ++) {
if ($i == $page_id) {
$str .= "
" . $i . "";} else {
$str .= "
" . $this->print_url ( $i, $i ) . "";}
}
$str .= "
" . $this->print_url ( "尾页", $total_pages ) . "";//return $str;
}
//return $str;
}
return $str;
}
}