Reputation: 97
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>
Upvotes: 1
Views: 67
Reputation: 913
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.
Upvotes: 1