I got a simple loadmore function, which sets the limit of a query and adds to the offset so only new items are loaded again. This works fine when I have 4 items to start with, but not when I want 8 to be displayed from the start.
My code:
var limit = 8;
var offset = 0;
$('#loadmoreprojects').click(function() {
limit = 4;
offset += 4;
ajax();
});
Query:
$project = "
SELECT ct.*, fe.*, cn.*
FROM 123_content ct
INNER JOIN 123_fieldsandfilters_elements fe on fe.item_id = ct.id
INNER JOIN 123_fieldsandfilters_connections cn on cn.element_id = fe.id
WHERE ct.catid IN ('10')
ORDER BY ct.ordering LIMIT ".$_POST['limit']." OFFSET ".$_POST['offset']."";
This shows 8 items from the start, but when loading more it shows the 2nd row again (the last 4 of the first 8 items). That makes sense because the limit is set to 4 again when clicking the button (because after the first 8, I only want 4 new items to be loaded) if I change it into 8, then 8 items are loaded on every click, which is not what I want.
How can I solve this?