Marking threads in a forum

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Dingbats
Forum Commoner
Posts: 25
Joined: Fri Dec 05, 2003 10:53 am

Marking threads in a forum

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Dingbats
Forum Commoner
Posts: 25
Joined: Fri Dec 05, 2003 10:53 am

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Dingbats
Forum Commoner
Posts: 25
Joined: Fri Dec 05, 2003 10:53 am

Post 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?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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.
Dingbats
Forum Commoner
Posts: 25
Joined: Fri Dec 05, 2003 10:53 am

Post by Dingbats »

Thanks! :D I'll try to develop an algorithm for doing that! :)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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. ;)
Post Reply