How do forums show you unread topics?

后端 未结 5 1149
刺人心
刺人心 2020-12-29 13:35

I have user discussion forums I coded in php/mysql, I am wanting to know how the big name forums can make it show you which topics have new posts in them, usually by changin

5条回答
  •  别那么骄傲
    2020-12-29 14:35

    The simplest way is to track the last time someone was logged in. When they come back to visit, everything which has been updated since then is obviously "new".

    This has some problems though, since logging out effectively marks all items as read.

    The only other way I could think to do it would be to maintain a table containing all the threads and the latest post in that thread which each user has seen.

    user_id   thread_id   post_id
          1           5        15
          1           6        19
    

    With that information, if there is a post in thread #5 which has an ID larger than 15, then you know there's unread posts there. Update this table only with the post_id of the latest post on that page. This means if there's 3 pages of new posts, and the user only views the first, it'll still know there's unread posts.

提交回复
热议问题