Home > php教程 > php手册 > body text

php 3行代码的分页算法(求起始页和结束页)

WBOY
Release: 2016-06-13 12:21:03
Original
823 people have browsed it

一个好的分页算法, 应该具有下面的优点:

当前页码应该尽量在正中间.
如果"首页"和"尾页"不可用(当前处于第一页或最后一页), 不要隐藏这两组文字, 以免链接按钮位置变动.
算法简单.
下面的算法具有前面1和3两个优点.

复制代码 代码如下:


// $curr_index, 当前页码.
// $link_count, 链接数量.
// $page_count, 当前的数据的总页数.
// $start, 显示时的起始页码.
// $end, 显示时的终止页码.
$start = max(1, $curr_index - intval($link_count/2));
$end = min($start + $link_count - 1, $page_count);
$start = max(1, $end - $link_count + 1);
start = Math.max(1, curr_index - parseInt(link_count/2));
end = Math.min(page_count, start + link_count - 1);
start = Math.max(1, end - link_count + 1);

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!