How to query 'additional 10' results from database in a React + Express server

Issue

I have a frontend built in React and a backend built in Express. I query my API from the frontend, and get back 10 results. This is the query in the backend

SELECT * FROM games LIMIT 10

Say I wan to implement infinite scroll. I’d like to query 10 more results, but not the same as before. What technique could I use, both/either on frontend or backend code?

Could I pass perhaps a number to my api string which gets incremented every time, e.g. 1st 10, then 20, then 30, to show the number of results, but how can I do that in a SQL query?

Solution

SELECT * FROM games LIMIT 10 OFFSET 10

Here you will get item 11 to 20. Now you can change the offset value to whatever you want.

Answered By – Gyanendro Kh

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published