Keeping track of read posts
Hi
How should I keep track of what posts a user have read in a forum? What I want to do is to present for the user a list of "Unread posts since your last visit". And when a user reads one of the posts it should be removed from the list.
The forum is stored in a MySQL database
Thanks,
//Tobbe McCain
Re: Keeping track of read posts
Quote:
Originally posted by McCain
And when a user reads one of the posts it should be removed from the list.
How would I do that part?
Re: Keeping track of read posts
Maybe it could be better to use a subscription kinda method? Like you'd have a table to keep track of what threads users are subscribed to then when a new post is made in a thread it will use that table to find out what users are subscribed to it and create an entry in an "unread" table so this list then ends up getting generated as posts are made rather than when they log on?
Subscription:
Code:
sub_id AUTO_INCREMENT PRIMARY
user_id
thread_id
Unread:
Code:
unread_id AUTO_INCREMENT PRIMARY
user_id
thread_id
Now when someone posts ina thread it will:
1. Use the querry:
Code:
SELECT `user_id`
FROM `Subscription`
WHERE `thread_id` = ThreadID
This will give a list of users that are subscribed to that thread.
2. Now for each of those users and an entry in the Unread table. First check it a record already exists that is the same though.
Now when choosing an icon for a thread you will just see if any records exist which have the user's user_id and that thread_id.
When they view the thread you just delete any records that have that thread_id & that user_id.
A slight chnage would be needed for the individual posts though. Just ask me if you need a hand with that :).
Re: Keeping track of read posts
I like the idea of subscribed threads for the list of new posts.
But if I use your idea that will also mean that when looking at the forum only subscribed categories with new posts will be marked as having new posts, right? Categories with new posts that the user isn't subscribed to won't be marked.
If that's how it is I don't think I will use that.
But thanks for keeping an open mind and comming with new ideas.
Re: Keeping track of read posts
Quote:
Originally Posted by McCain
I like the idea of subscribed threads for the list of new posts.
But if I use your idea that will also mean that when looking at the forum only subscribed categories with new posts will be marked as having new posts, right? Categories with new posts that the user isn't subscribed to won't be marked.
If that's how it is I don't think I will use that.
But thanks for keeping an open mind and comming with new ideas.
Good point but for the categories.
What you could do is run a querry to find out the date/time of the last post in that section. Then compare it with the last time the user logged in. This gives the style of the last version of vBulletin where to mark a forum read you had to select it from an option, this could be implemented by each forum having one of these date/times (like I said use your last logged in time) then when they mark it as read it replaces the time with the current.
A problem with this still is on the forum display it would only show subscribed threads as unread, all others would be unread. :(
Re: Keeping track of read posts
The thing with just checking the date/time is that even if you don't read all the posts in a topic/thread while you're logged in that topic/thread will be marked as read the next time you log in as there are no new posts since you last logged out.
Or did I not understand what you ment?
Re: Keeping track of read posts
Yea the last line in my post I pointed out with that method all threads would be marked as unread unless you were subscribed to them :(.
Which method are you going for BTW? The one where you generate a "Read" list as you go? Or the one where you create a "Unread" list at the begining?
Re: Keeping track of read posts
I think this is what I'll do:
1. Try to code the stuff I talked about in post #22 (list of unread posts).
2. Come back here with more detailed problems :D
Thanks for your help so far
Re: Keeping track of read posts
I have now made it so that I keep track of when a user loggs out, so I get a date/time to match against the posts.
But I'm not very good at SQL, so I need a little help with translating this psuedo SQL into real SQL...
PHP Code:
$query = 'SELECT topic, lastdate FROM forumtopics WHERE lastdate > (SELECT timestmp FROM ppl WHERE usrname = "'. $_SESSION['usrname'] .'")';
topic is the thread title.
lastdate is the date and time of the last action in that topic/thread, like a new post or something.
timestmp is despite the name actually a DATETIME field in the database.
The rest should be pretty obvious
Thanks
Re: Keeping track of read posts
first thing to note is I'm not sure your allowed to do nested statements in mySQL. In oracle I was able to but when doing it for my site with mySQL it does allow it. So you'd have to do this as two querys bit like this:
PHP Code:
$query = "SELECT `timestmp` ";
$query.= "FROM `ppl` ";
$query.= "WHERE `usrname` = '". $_SESSION['usrname'] ."' ";
$results = mysql_query($query);
$Result = mysql_fetch_array($results);
$query = "SELECT `topic`, `lastdate` ";
$query.= "FROM `forumtopics` "
$query.= "WHERE `lastdate` > ".$Result['timestmp']." ";
$results = mysql_query($query);
Unless your SQL server allows nested statements?
Re: Keeping track of read posts
Yeah, I have two statements now, was just hopeing I could do it with one.
Technocrat's question was also about nested statements and that was doable in one query.
I tried doing mine in a similar way but couldn't figure out how to do it.
I'm using mySQL.
Re: Keeping track of read posts
Thanks for all your help Electroman. This part of my forums are working like I want it now.
Now I can move on to add moderator functionality, like moving threads and stuff. Butt if I need help with that I'll make a new thread.
Thanks again Electroman (and you too visualAd)