I'm creating a Pinterest-type image-type site that, in addition to other things, needs to combine the following features:
Infinite Scrool (I'm applying this code here: link ).
A menu to choose in which order to display the images.
The problem happens when I choose to display the images randomly: they repeat themselves.
The query I'm using is as follows:
$return = $database->query("
SELECT
lk_post_pic.*,
tb_post.head,
tb_post.created_datetime,
tb_pic.album,
tb_pic.file,
tb_pic.thumbnail
FROM lk_post_pic
JOIN tb_post ON lk_post_pic.fk_post = tb_post.id_post
JOIN tb_pic ON lk_post_pic.fk_pic = tb_pic.id_pic
WHERE tb_pic.thumbnail = 'default'
ORDER BY RAND()
LIMIT 20
OFFSET $offset
")->fetchAll(PDO::FETCH_ASSOC);
Each time the scroll scrolls to the bottom, this query is executed again and the $ return data is inserted into a tamplate html, through the echo, which is received by the jQuery function as a response to the GET, and in then the append () method is executed.
NOTE: I hope I'm not complicating this digression, it's just to contextualize, maybe I can help.
So, every time this query is executed, the $ offset is increased by 20 units to start the new images, but since everything is randomized before, the images of the first offset end up mingling with that of the second and hence the views are repeated.
How to work around a problem?