On page load, 5 items are selected from the database. As the user scrolls down, 5 more posts are loaded, etc.
To prevent duplicate posts when sorting by 'new', I place the page load time in a hidden input to be used in JavaScript:
<input id="loadTime" type="hidden" value="<?php echo time(); ?>">
Then when fetching more posts while scrolling I only select new ones from before that time to prevent duplicate posts.
WHERE s.date < :loadTime
However, my issue is when sorting by Hot or Top, because it doesn't use the same logic.
Is it possible to detect if two elements on the page have the same ID? Because when a duplicate post is appended to the page, it will have the same ID as one already on it. Some sort of $(window).scroll()
have a function that removes the duplicate ID afterwards so that the user doesn't see duplicate posts?