ajax noob here
I have a web page which cycles through images and I want it to go to the next one when you press the next arrow - how do I handle showing new images if someone uploads an image while the user is already on the page?
>home.php shows an image
>press button for next image
>someone else uploads an image
>how to include new pic in the flow
One option would be to consistently poll the backend for a list of the images stored in there. If there's a timestamp attached to each image, it'll be quite easy to see if more images can be shown.
Second option that comes to mind would be to utilise web sockets. Send the information of the new image to all the clients.
Or then you could implement it so that each time you press the arrow, it fetches a list of the images and then loads the image following what's currently being shown.
Many options, each of them is useful in their own way, largely depending on your use-case.
and what's the best way to let a user cycle through the content when new content is added constantly?
say they start at post 4 then go to 3, 2, 1, then a post 6 and five is added
it seems a bit resource intensive to have a cookie remember which ones they've seen
-
equally it will get annoying if they veiw all of the content in the same order (most recent to oldest), they might see content many times but next veiw the oldest content
>>58911723
thanks for the reply
yes they all have upload date/time stamps recorded on an SQL database
I can see how it would be easy to show them all the pics in descending order then show the ones since they logged on in ascending but it will be for regular users who will check back for not just new but all UNSEEN images
I want it to show all unseen images before cycling through old ones - a bit like tinder except when you're done it lets you see old ones again
Consider sending a state to the backend when fetching a new image.
In the scenario where you have images:1, 2, 3, 4
And the user views 1 and 2, then image 0 is uploaded, if the client keeps track that the min-image seen is 1, and the max-image viewed is 2, you can check in the backend if there exists a newer image than 1 (which would be 0 in this case) and if it doesn't, pick the next one from the max-image sent by the client (3).
http://php.net/manual/en/class.iterator.php
>>58911673
Use jQuery.