tags:

views:

172

answers:

5

I'm working on a site where users submit photos which can be viewed one by one on a page.

There is another page where you see smaller versions of multiple photos.

When user clicks any of these smaller photos they get the large version page, pressing "next" will take them to another photo in that category.

I would very much like newer photos to have precedence over older photos.

My idea is that when user clicks next he is taken to the newest photo and moving next from there will take user backwards through all the new photos.

Problem is, when user leaves single photo page, goes back to multiple thumbs page and then clicks another photo there, user will start seeing the same new photos when clicking next.

I would like to ensure user does not see same photo. I thought about putting a unique cookie for each visitor and then when user vistits photo I record it in a visits table. When selecting new photo from db for 'next' I ensure that user has not visited that photo before.

I am (prematurely) worried about what effect this will have on database load.

Any ideas about what is the best way of doing this or an alternative method?

edit: Might not have been clear enough, very short version: I want to ensure no duplicate content when cycling through pictures. Preferably over an extended time, not only a session.

A: 

If you're using sessions, you could keep track of the oldest 'new' photo ID that a user has viewed. So when they click next, you show the newest photo and store its ID in the user's session. Each time they click next, give them the newest photo you have that is lower than the ID of the photo they have in their session. This way, your session will always know where to start to show them a relatively new photo that they haven't seen yet. You can just keep moving through photo records from wherever they left off.

Since sessions use cookies to work, this will work until they clear their cookies, even if they don't register or login.

This won't take into account new photos that have been submitted or uploaded since the user started browsing, however. Without storing a record of each individual photo the user has looked at, it's going to be very challenging to figure out a way to simulate that level of record-keeping.

Edit:

Thinking more on this, you could store not only the oldest photo ID the user has viewed, but the newest. That way, each time they click next you see if your newest photo is newer than the newest they have viewed. If so, show them the newest photo. If not, show them the newest photo you have that is older than their "oldest viewed" photo.

Brett Bender
I thought about this solution but when user comes next day he will start from scratch. I am probably being unrealistic about keeping such an extensive user history and go for this solution :)
Amything
Yes, php session's don't last forever. You could store the user's last-visited photo ID in the database with his user record. This way they wouldn't start over every day, but this still doesn't solve the "new photos" issue.
Brett Bender
A: 

I can't quite tell what you mean exactly, but all you want to do is order your photos with ids based on when the item was added (highest = newest) and decrement the id when you hit next, that way they can jump into the viewing queue wherever and clicking next will just move to the next in line photo.

Edit: From what it sounds like you will need to store user unique variables on what they have viewed and what they have not.

From your other responses you want it over an extended time frame.

If you are not willing to reduce it to a session length time frame (the simpler implementation) you could store the views in a database like you suggest.

To address your concern about disk space, you can do all sorts to reduce it.

To name a one: - Store individual views but where possible store view sequences. Compression in a simple form. So user views id 1,2,3,4,6,12,13,15. Your db views table might look like: View

UserID  ImageIDStart  ImageIDEnd
jim        1             4
jim        6            null
jim        12            13
jim        15           null

You may want to split those concepts into two tables, 'sequences' and 'individual views' that would allow proper querying and easier processing. You would want some form of compressor that takes individual views and converts to sequences where possible though.

jim
Might not have been clear enough, very short version: I want to ensure no duplicate content when cycling through pictures. Preferably over an extended time, not only a session.
Amything
A: 

When the 'image viewer' closes, you could simply store the begin id (first photo the user sees) and id of the photo the user saw last.

When the user comes back, you can simply check if there where newer photo's added, if so, display those first, until you arrive at the id of the image the user saw first (stored in cookie, or database). then just skip till the id of the image the user saw last, and continue from there.

This will not generate a huge overhead on cookies / sessions or databases.. and it is basically fool proof .. at least relatively accurate, up till some point where you have to fix issues like; what if the user drops in at the middle of a range of photo's? You could store a range of id's, obviously..

Tons of solutions like this. Just think 'smart'. And take in consideration the need for precision. If you put a record in a database for each visited photo, you will have a precise recollection of what the user saw, but performance will most likely drop (dramatically over time, I can assure you). If you like performance, and I'm sure your users will, then I'd suggest you take a look at a solution that might be less accurate (like described above) but respects performance.

MiRAGe
A: 
Amything
Its scaled down, full size: http://amything.googlepages.com/next.jpg
Amything
What happens when the user doesn't get back to where they started again and leaves. I still don't get the reason behind wanting to do it this way. Usually images will still be cached and load fast so they can just spam hit the next key till they find the new items. Also, I hope you're not going to call the link 'next' while image 50 goes to 103. That would confuse me.
jim
A: 

Are your users logged into your site? Do you have anyway to tell them apart server side?

Code Monkey