论坛如何向您显示未读主题?

发布于 2024-08-16 16:28:16 字数 80 浏览 8 评论 0原文

我有用 php/mysql 编码的用户讨论论坛,我想知道知名论坛如何向您显示哪些主题中有新帖子,通常是通过更改线程旁边的图标图像而不使用任何资源?

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 changing an icon image next to the thread without using hardly any resources?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一指流沙 2024-08-23 16:28:16

最简单的方法是跟踪某人上次登录的时间。当他们回来访问时,自那时以来更新的所有内容显然都是“新的”。

但这有一些问题,因为注销实际上将所有项目标记为已读。

我能想到的唯一其他方法是维护一个包含所有线程以及每个用户所看到的该线程中的最新帖子的表。

user_id   thread_id   post_id
      1           5        15
      1           6        19

有了这些信息,如果线程 #5 中有一篇帖子的 ID 大于 15,那么您就知道那里有未读的帖子。仅使用该页面上最新帖子的 post_id 更新此表。这意味着如果有 3 页新帖子,并且用户只查看第一页,它仍然会知道有未读的帖子。

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.

我还不会笑 2024-08-23 16:28:16

正如 nickf 上面所说,除了跟踪用户实际访问过的线程。因此,用户未访问过的任何内容对于该访问者来说都被认为是新的。为了更细粒度的控制,在用户注册之前创建的任何线程都将被忽略,并且可能会忽略一段时间内未访问的任何线程。这将防止每个未访问的线程成为它们的新线程。

当然,剥猫皮的方法有很多种,根据论坛创建者的需求,可以更改上述内容以适合

DC

As nickf said above except that the threads the user has actually visited is tracked. so anything the user hasn't visited is considered new for that visitor. for finer grain control any threads created before the user registered are ignored and possibly any threads not visited within a period of time are ignored. this would prevent every unvisited thread as becoming a new thread for them.

Of course there are many ways to skin a cat and depending on what the forum creators wanted the above can be changed to suit

DC

呆橘 2024-08-23 16:28:16

您可以记录他们上次选择该主题的时间,然后查看帖子的时间戳是否晚于他们在线程上的最后一次“点击”。

You could log the last time they selected that topic and then see if a post has a later time-stamp then their last "click" on the thread.

标点 2024-08-23 16:28:16

您可以在数据库中创建一个特殊的表,其中包含 USER_ID 和 THREAD_ID 等列,并对 USER 和 THREAD 表进行适当的约束,并使用包含 USER 和 THREAD ID 的主键。

现在,当有人打开一个线程时,您只需将该用户线程对插入到该特殊表中即可。

在您的线程列表中,您现在可以简单地将该表外部连接到适合您在那里使用的内容。如果您的新表在任何特定位置包含 NULL,则该线程未被读取。这将启用如下列表:

  • 所有带有“未读”标记的线程
  • 所有未读线程
  • 由用户 XY 读取的线程

如果您向此表添加日期列,您可以做更多有趣的事情。

只需留意您的键和索引,以防止过大的负面性能影响。尝试仅通过将 USER-THREAD-表加入到现有查询中来读取它。这比一直执行单个查询要快得多。

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.

峩卟喜欢 2024-08-23 16:28:16

您可以有一个表,每当读取线程时,如果用户尚未读取该表,该表就会获得插入。然后,当有人添加到线程时,您可以删除该线程表中的所有条目,从而使所有用户都无法读取它。

表结构类似于

forum_id thread_id user_id

为主键添加可选的额外 has_read_id ,其他字段构成复合键。

You could have a table that gets an insert whenever a thread gets read, if the user reading it hasn't already. Then when someone adds to the thread you can delete all entries in the table for that thread, thus making it unread for all users.

The table structure would be something like

forum_id thread_id user_id

With the optional extra has_read_id for your primary key, with the other fields making a composite key.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文