views:

35

answers:

1

Hi,

I'm doing a forum script in php, i'm trying to think the best way to flag topics each user has read or not.

Once the user logins into forum i can mark what's been read or not depending on his last login time, that's fine, now what's the best approach to mark each topic each user clicks?

I was thinking in adding cookies but that would lead to a security issue and might not be accurate, specially if the user logins from another machine/browser.

I also thought of adding a special database table with each topic each user has clicked, that also sounded bad for me due the incrase on cpu usage and database growth.

Anyone has a better suggestion/solution?

Thanks.

+1  A: 

You can keep a separate database table to keep a record for every topic X every user if the user has read it (no record if the user hasn't), and then automatically assume after 30 days that the topic is read, which allows you to prune this table to prevent overgrowth. Keeping a separate table like this is pretty standard practice, and unless this forum is super popular (always plan for popularity I guess), I doubt you'll run into space or CPU limits.

For example, table topics_read has fields user_id, topic_id, and when. Storing two ints and a date is only a few bytes for each row.

erjiang