Page 1 of 1

Marking threads in a forum

Posted: Tue Oct 12, 2004 12:38 am
by Dingbats
I'm coding a forum for my site, and I need to mark the threads that have new posts in them since the user who browses the forum last read them. I tried doing this before, but it didn't work.
How would I do it? What is teh best way to do it? I don't want to use cookies, since they exist only on one computer; the user wouldn't be able to log in and check which threads are unread from another computer.
Any help?

Posted: Tue Oct 12, 2004 4:01 am
by twigletmac
A start would be to have a last logged in time for each user that you can check against thread's modification times.

Mac

Posted: Tue Oct 12, 2004 9:02 am
by Dingbats
I have. Though I don't want to check against the login time, I want to check against the last time the user read the thread.

Posted: Tue Oct 12, 2004 10:28 am
by twigletmac
This would become very difficult to manage as you would need a table full of records of threads users have accessed and at what time. Basically for each thread you would need to store a user ID and access date/time for each user that views that thread.

Mac

Posted: Wed Oct 13, 2004 8:35 am
by Dingbats
Exactly.
I might be lazy, but:
Can any one please please please post some sort of way to solve the problem, not including the code, just how I would solve everything with db tables and stuff. Please?

Posted: Wed Oct 13, 2004 9:10 am
by kettle_drum
Think the problem through logically. How do you know that a user has read a thread? You log the time they load that page. How do you then know if there is a new post? You see if a new post has been posted since they looked. How do you check this? Compair the times.

Then think - omg imagine that i have 1000 users and 100 threads, that means i need to hold info on 100 threads for 1000 users - thats a lot. What can i do to reduce that? Only store info if they have viewed a thread - if theres no info on the thread from that user then they havent even looked at it.

What would reduce the amount of data i need to store more? How-about every time a new post is posted in a thread i remove all the data saying that a user has read that thread. This way i dont care about times, i just care that a new post has been submitted since they last looked.

Using that method:

Database:

Code: Select all

CREATE TABLE view_threads (
   user_id
   thread_id
);
When a user views a thread add the user id and the thread id to this table. When a new post is submitted delete all entried in the table that hold that thread id.

Still be warned that this could end up holding 10000's of entries - so you might want to remove threads that are inactive from this table - say after a month of no posts.

Posted: Thu Oct 14, 2004 12:48 am
by Dingbats
Thanks! :D I'll try to develop an algorithm for doing that! :)

Posted: Thu Oct 14, 2004 2:22 pm
by JAM
kettle_drums warning is true indeed, and I can add some more theoretical ideas.

base64_decode/encode, serialize/unserialize are php functions that might be worth looking into (there are others, I just mention these more common ones).
Say you have an array of viewed topics,

Code: Select all

$viewed = array('1','5','435');
and user serialize() on that, you get an database insertable string. Retrieving that that line later, unserialize()'ing it, and you again have the viewed topics as an array.

Depending on how advanced the forum is and whatever functions it contain, the above might be of interest after some rewriting. It's also an common way to send data across pages using sessions and it's likes. It might not be suitable for this purpose at all, but I just wanted to broaden the horizon.

Hope we see some previews of it later. ;)