Re: check unread messages in a forum
| From: | Richard Lynch | Date: | Mon, 26 Aug 2002 23:07:23 +0000 |
| Subject: | Re: check unread messages in a forum | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-114195@lists.php.net to get a copy of this message | ||
>I have made a forum in PHP, and the users are logged in using cookies. I
>want all new threads (and if there are new replies in an old thread) to be
>highlight or something like that.
>
>How do I check if a user has read a message or not?
Every user has a unique ID when they log in, right?
And every message has a unique ID, right?
create table messages_read(
user_id int(11) unsigned not null key,
message_id int(11) unsigned not null key
);
When they read a message:
$query = "insert into messages_read(user_id, message_id) values($user_id,
$messages_id)";
You can then use this in the query that gets the messages for display:
select blah, blah blah, messages_read.user_id from messages
left outer join messages_read on user_id = $user_id and
messages_read.message_id = messages.message_id
where blah, blah, blah
The "left outer join ..." part is the new bit in your query.
Notice also that I've added "messages_read.user_id" to the columns you
select.
As you iterate through the messages to display, either:
1. messages_read.user_id is their $user_id, and they've read that message
or,
2. messages_read.user_id is NULL because there was no row in the
messages_read table, so they ain't seen that message yet.
Be sure to add interface elements so that they can mark a message "Read" or
"Unread" even if they've already read it or haven't -- Let the user have
control over what they consider as "Read" or they'll be only partially happy
about this new feature. :-)
--
Like Music? http://l-i-e.com/artists.htm