Ram prakash Singh
Ram prakash Singh

Reputation: 31

How to create pagination in express with MySQL database?

I want to use pagination in express with MySQL database. I have read many more posts for use pagination in express but did not find any post to solve my problem. I have found the post which use in pagination in express with monogodb but I want with MySQL.

Upvotes: 0

Views: 2407

Answers (1)

user5383152
user5383152

Reputation:

Use LIMIT and OFFSET while querying your data.

For example, to get the first 30 data, you use

SELECT * FROM DATA LIMIT 30;

And to get the second page, use

SELECT * FROM DATA LIMIT 30 OFFSET 30;

In your Express app, make page as one of the params you process in the API logic. That simple.

Upvotes: 5

Related Questions