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?
Marking threads in a forum
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
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:
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.
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
);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.
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, 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.
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');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.