Page 1 of 1

Marking posts as read - how is it done?

Posted: Wed Aug 13, 2003 1:13 pm
by RFairey
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?

Posted: Wed Aug 13, 2003 3:35 pm
by JAM
You could use serialize/unserialize...

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

Posted: Wed Aug 13, 2003 4:14 pm
by Coco
aye as jam said, the best way is normally to store an array (serialised or not) in a cookie.

your array would probably be something like
$thingy[#thread_number#] => $time_visited
or on a larger site you would use the forum number rather than the thread number

Posted: Thu Aug 14, 2003 10:36 am
by RFairey
Would this work to put a php array into a mysql database? Put values into array -> serialize -> stick serialized data into mysql table -> read from table -> unserialize -> use?

I am thinking more along the lines of an array for each post containing the users that have read it.