I have an AJAX system that fetch posts from database and then create DIVs in my layout to put them. When te user reachs the end of the page then many other posts will be loaded by the API. The problem is, how can I get the following 10 posts that are just the previously posts of the last that is already loaded? The same thing I want to happen when I load the new posts at the top, how to show every post in the right order without missing any post or duplicating any post?
Sorry for the bad explanation and the bad english.
You need to store the id of the last retrieved message. When you submit the new request, send the last received message id and have php/mysql return the results from there.
If your query looks something like this:
Then you’d need to modify to be something more like:
You could alternatively use the offset method that Scott mentions.
Edit: I assumed you were using auto-increment ids because it’s so common. Since you aren’t, you need some way to keep track of the last message returned. You can do this through sorting the records in a way that they’ll come out in the same order every time and use offsets.