How do forums show you unread topics?

后端 未结 5 1175
刺人心
刺人心 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:18

    You could make a special table in your database with columns like USER_ID and THREAD_ID and with appropriate constraints to your USER and THREAD tables and a primary key containing USER and THREAD IDs.

    Now when somebody opens a thread, you just insert that USER-THREAD-PAIR into that special table.

    In your thread listings you can now simply outer-join that table on to what ever suits you use there. if your new table contains NULL on any particular spot, that thread is unread. This will enable lists like:

    • All Threads with "unread" marker
    • All unread threads
    • Threads read by user XY

    If you add a date column to this table, you can do even more interesting stuff.

    Just keep an eye on your keys and indexes to prevent too heavy negative performance impacts. Try to read from the USER-THREAD-table only by joining it into your existing queries. That will work much faster than executing individual queries all the time.

提交回复
热议问题