php用什么函数分页,常用php分页函数

常用php分页函数…

/**

*函数print_paging

*功能:实现分页

*将分页的导航制作包装成一个表的格式

*分页导航格式,例如如下格式:

*/

//

几页/几条首页1234567尾页

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;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值