What is the best way to select objects from the database by portions (MySQL)?

3323 views mysql
4

I have the database with 1000+ objects. I want to make a button, by pressing which the first 20 objects from DB will be selected and loaded. If I press this button again, next 20 objects will be loaded and appended to previous objects. How to do this? Which SQL commands will help?

answered question

1 Answer

5

MYSQL:

SELECT * FROM table LIMIT 20 OFFSET 0;
SELECT * FROM table LIMIT 20 OFFSET 20;
...etc

Then you would just need a way to keep track of the offset variable. You could use a session variable or a hidden variable on the page. I'm sure there are other ways.

posted this

Have an answer?

JD

Please login first before posting an answer.