How do forum systems such as phpBB mark posts as having been read by any particular user? By this I mean how do they keep track of when to tell a user there are new posts since their last visit?
I am building a simple forum, I have posts stored in a mySQL database, each with a timestamp. User logins are also recorded, with a second timestamp. It is not sufficient to merely compare the post time and login time, since as soon as a user posts, his own post gets marked as being new. Also, a user may not necessarily view a post that is new, and this should remain 'unread' as it were across any number of logins until it is viewed.
What sort of data structure is used to keep track of all this? Is it feasible to store an array of users in the info of a post or vice versa?
Marking posts as read - how is it done?
Moderator: General Moderators
You could use serialize/unserialize...
You could use the serialized value in a cookie for example, because such string are easier stored. Then read the cookie, and unserialize it, to restore the original values...
Code: Select all
// set some values
$array[] = 'foo';
$array[] = 'some string goes here';
$arrayX[] = 'bar';
$arrayX[] = 'kittythrow';
$arrayX[] = $array;
// see what you have done...
print_r($arrayX);
// serialize the data, show result
$foo = serialize($arrayX);
echo $foo."\n";
// un-serialize the data, show result
$foo = unserialize($foo);
echo $foo."\n";
// oh my, it's an array, lets make that better looking...
print_r($foo);