Bulletin board page processing problems

Asked 2 years ago, Updated 2 years ago, 113 views

Hi, everyone.

I uploaded it because I had a question about the processing of the bulletin board page.

To know the size of the page itself when implementing pagination on the web

Don't you need the total number of posts?

SELECT count(*) FROM articles;

The count query takes more than a second from a table that currently has about 200,000 posts.

Pagination is

Previous 1 2 3 4 5 6 7 8 9 10 Next

It is implemented in this way, and the last page is

after receiving the page size.p

Previous 20202203 Next

I'd like to close the last page like this.

Is there another way to get the number of pages without using the total count?

I'd like to know how it's usually implemented!

pagination mysql ruby-on-rails

2022-09-22 21:57

1 Answers

Basically, if you don't know the total number of rows, you can't accurately calculate the number of pages.

Calculating the total number of rows is a very large operation, so you usually do not expose the total number of pages.

As an alternative, scan using the cursor of the data sorted by offset, limit as shown below.

If the query below is page 1, page 2 will be LIMIT 11, 10.

SELECT * FROM table ORDER BY id DESC LIMIT 0, 10;

The attachment is a pagenation image that Google is using. There's no total count, right?

.


2022-09-22 21:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.