1

I try to code a loadmore Script.. But connected with a Database means onPage load its showing the first 20 Posts... Then at Page complete scrolling down or clicking the loadmore Button after at bottom of Page its loading the next 20 Posts.

But at the moment its showing everytime the same Posts and its only working with the Button onclick.

So what is the right way ? Or what i must change ?

Thanks for all Hints.

I use atm a simple Ajax Request.

<script type="text/javascript">
$(document).ready(function(){
 $( ".readmore_home_posts" ).click(function() {

            $('div#loadmoreajaxloader').show();
                $.ajax({
                    url: "./ajax/loadmore_homenews.php",
                    success: function(html){
                        if(html){
                            $("#lastPostsLoader").append(html);
                        } else{
                            $('#lastPostsLoader').html('<center>No more posts to show.</center>');
                        }
                    }
                });

});
});
</script>
1
  • Can you show your loadmore_homenews.php file? The problem may lie there. Commented Aug 31, 2015 at 1:25

1 Answer 1

1

You haven't done anything to tell the database which records to load, so it will always load the same records. You can remedy this by using some sort of counter and passing the counter number to the loadmore_homenews.php page as part of the data or even as a $_GET var, something like

url: "./ajax/loadmore_homenews.php?counter=" + counter

Then use the counter var as part of your db query, limiting the rows selected based on the counter.

Sign up to request clarification or add additional context in comments.

2 Comments

This wouldnt work ? .. Cause how to say it that it load another 10 ... and not again all 10 / 20 / 30 Posts ?
Use MySQL's LIMIT and OFFSET feature, so that your query would be something like: SELECT * FROM posts p INNER JOIN friends f ON ((p.from_user=f.user1 OR p.from_user=f.user2) AND (f.user1='$ownid' OR f.user2='$ownid') AND f.accepted='1') GROUP BY p.id ORDER BY p.uhrzeit DESC LIMIT 20 OFFSET '$counter' ; "); So this would select the next 20 rows, starting at $counter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.