Paging algorithm for PHP 3 line code (for the start page and end page) _ PHP Tutorial

Source: Internet
Author: User
The paging algorithm of the php3 line code (for the start page and end page ). A good paging algorithm should have the following advantages: the current page number should be in the center as much as possible. if the homepage and the last page are unavailable (currently on the first or last page), do not hide these two good paging algorithms. they should have the following advantages:

The current page number should be in the middle.
If the "homepage" and "last page" are unavailable (currently on the first or last page), do not hide these two groups of text to avoid changing the link button position.
The algorithm is simple.
The following algorithms have two advantages: 1 and 3.

The code is as follows:


// $ Curr_index, current page number.
// $ Link_count, number of links.
// $ Page_count: the total number of pages of the current data.
// $ Start indicates the start page number.
// $ End: the ending page number displayed.
$ 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 );

Should have the following advantages: the current page number should be in the middle. if the "homepage" and "last page" are unavailable (currently on the first or last page), do not hide these two pages...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.