Robert Azar Sammie
Robert Azar Sammie

Reputation: 152

How do you load more post in news feed without loading previous loaded post?

This code is in my index page:

SELECT * FROM post ORDER BY posting_id DESC LIMIT 15
newPost = newPost + 15;
canBeLoaded = false;
$(".newsfeed").load("https://www.veenir.com/home/post/autoloadposts/posts.php", {
        newPost: newPost
    },
    function(b, c, d) {
        if (c == "success") {
            canBeLoaded = true;
            $(".loadingMorePostIndicator").html("<span></span>");
        }
    }
});

This code is in my autoloadposts folder; it gets the value of the loaded posts and adds 15, before reloading the posts from the database with the new limit each time the user reaches the bottom of the page:

SELECT * FROM post ORDER BY posting_id DESC LIMIT $newpostcount

Upvotes: 0

Views: 168

Answers (1)

Sentry
Sentry

Reputation: 81

You can do it in one SELECT query by setting a different LIMIT:

SELECT * FROM post ORDER BY posting_id DESC LIMIT $oldpostcount, 15 //$oldpostcount + 15 elements will be selected

The var $oldpostcount has to be your current called amount. Lets say you have already called your first 15 items from your Database. Then you set $oldpostcount = 15; and reload the page with this var. Now all your posts from 15 to 30 will be selected. You can search for "MySQL Infinite Scroll" if you need more information about that.

Upvotes: 1

Related Questions