custom php forum - showing new/unread posts

后端 未结 5 2266
臣服心动
臣服心动 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:17

    Hmm, good question.

    I will toss my two cents in on how I would handle this, it may not be the most efficient solution, but here goes:

    I would use a database to solve this problem. If possible create a field in the database that attaches to a specific user. Inside this field (or column or table if you prefer) store a list of "viewed" articles by the article ID.

    When rendering the page for the user, retrieve their list of "viewed" articles and a list of all the article ID's available.

    Loop through your Article/forum/topic result set and see if that ID matches any of the "viewed" ID's. For every Article/forum/topic entry that does not have a corresponding "viewed" match, then to that user it would be a "new" article.

    This is processor/database/network intensive and requires a look up to the database each time a page is loaded that contains article references. Although with a bit of clever query design I think you could offload this kind of operation almost entirely to the database.

    Also another potential solution using the database, would be that when a user first logs into the site, you fetch a list of read articles/forums at that first load point and add it to a cookie or session, this way you only hit the database for that list once (on first load), and store it in a session/cookie/hidden field, so that in subsequent requests you would only have to go to that cookie/session/hidden field instead of performing a Db look up each and every time the user views a page with a list of articles/forums/topics. Each time the user clicks a link, capture and store it in the database, and also store that article/forum ID in your cookie/session/hidden field. Once again, perhaps not the most efficient method, but with some good old fashioned gumption I am sure you will prevail. :)

    Best of Luck to you!

    H

提交回复
热议问题