Paging algorithm for php 3 lines of code (finding the start page and end page)_PHP tutorial

WBOY
Release: 2016-07-21 15:43:15
Original
853 people have browsed it

A good paging algorithm should have the following advantages:

The current page number should be in the middle as much as possible.
If "Home" and "Last Page" are not available (currently on the first or last page ), do not hide these two sets of text to prevent the position of the link button from changing.
The algorithm is simple.
The algorithm below has the two advantages of the previous 1 and 3.

Copy code The code is as follows:

// $curr_index, the current page number.
// $link_count, the number of links.
// $page_count, the total number of current data Number of pages.
// $start, the starting page number when displaying.
// $end, the ending page number when displaying.
$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);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320775.htmlTechArticleA good paging algorithm should have the following advantages: The current page number should be in the middle as much as possible. If "Homepage" and "Last Page" are not available (currently on the first or last page), do not hide these two...
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 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!