PHP paging function

Source: Internet
Author: User
PHP paging: how does one implement Baidu paging?


Reply to discussion (solution)

I have no question...

The page size should be almost the same. baidu also passed a parameter & pn = 0.
Determine the page number based on the pn value and take a footprint for image processing? And so on.

If you are talking about 1 2 3 4 5 display
Paging procedure
1. calculate the total number of items
2. get the current page
3. calculate the total number of pages ceil (total number of pages/Number of pages per page)
4. the calculated offset is limit n, m
5. query data display data

Note: The third part shows the total number of pages. suppose it is 10 pages.

$str = '';    for($i=1;$i<=10;$i++){        str .= ''.$i.'';    }echo $str;

In this way, the 12345 effect will come out.
Then click style.
a{    width:20px;    height:20px;    display:block;    background:#ffffff;    border:1px dashed #ccc;    color:blue;}a:hover{    background:blue;}

It's almost so sloppy.

If you are talking about 1 2 3 4 5 display
Paging procedure
1. calculate the total number of items
2. get the current page
3. calculate the total number of pages ceil (total number of pages/Number of pages per page)
4. the calculated offset is limit n, m
5. query data display data

Note: The third part shows the total number of pages. suppose it is 10 pages.

$str = '';    for($i=1;$i<=10;$i++){        str .= ''.$i.'';    }echo $str;

In this way, the 12345 effect will come out.
Then click style.
a{    width:20px;    height:20px;    display:block;    background:#ffffff;    border:1px dashed #ccc;    color:blue;}a:hover{    background:blue;}

It's almost so sloppy.




How does Baidu calculate the page number range?
Currently, 1 ~ is displayed before 7 ~ 10
Current page 7 2 ~ 11
...
Current page 10 5 ~ 14
How is this calculated?

Very easy. I recently made a paging-proficient ppt. you can share it with me.


If you are talking about 1 2 3 4 5 display
Paging procedure
1. calculate the total number of items
2. get the current page
3. calculate the total number of pages ceil (total number of pages/Number of pages per page)
4. the calculated offset is limit n, m
5. query data display data

Note: The third part shows the total number of pages. suppose it is 10 pages.

$str = '';    for($i=1;$i<=10;$i++){        str .= ''.$i.'';    }echo $str;

In this way, the 12345 effect will come out.
Then click style.
a{    width:20px;    height:20px;    display:block;    background:#ffffff;    border:1px dashed #ccc;    color:blue;}a:hover{    background:blue;}

It's almost so sloppy.




How does Baidu calculate the page number range?
Currently, 1 ~ is displayed before 7 ~ 10
Current page 7 2 ~ 11
...
Current page 10 5 ~ 14
How is this calculated?



Assume that the current page number is $ page.
$ First_page = max ($ page-5, 1 );
$ End_page = $ first_page + 9;

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.