custom php forum - showing new/unread posts

后端 未结 5 2245
臣服心动
臣服心动 2021-02-14 23:26

I have written myself a custom forum script using php. I decided against using phpbb and others as I wanted 100% flexibility with what I was doing.

I\'ve hit a problem

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-15 00:18

    A lot of the larger forum software uses a tracking table to keep up with who has read what, something like this (heavily simplified):

    CREATE TABLE topic_tracking (
        user_id INT NOT NULL,
        topic_id INT NOT NULL,
        last_visit DATETIME NOT NULL,
        PRIMARY KEY (user_id, topic_id)
    )
    

    You then use a join on this table to check if a post you're displaying is read or not. Since you'll be paging your threads, this should generate relatively few additional queries (depending on how many posts you show per page).

    When a user visits the thread, update this tracking table with the timestamp of their visit. Then when displaying your thread links, check this table to see if their last_visit is earlier than the last post in the thread. This also lets you show "updated" threads, not just "new" ones.

提交回复
热议问题