自定义php论坛 - 显示新的/未读的帖子 [英] custom php forum - showing new/unread posts

查看:441
本文介绍了自定义php论坛 - 显示新的/未读的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自己写了一个自定义论坛脚本使用php。我决定不使用phpbb和其他人,因为我想要100%的灵活性与我在做什么。



我遇到一个问题,虽然:



如果某条信息是新的/未读的,我该如何显示。



有两种解决方案:



1)Cookie
2)数据库



我不想使用cookie,因为他们可以被用户删除而firefox端的东西意味着它们被自动删除。无论哪种方式,我不想使用cookie。



数据库导致我的一个问题,因为我似乎无法得到数据库结构排序在我的头!我可以想到的第一个解决方案是:




  • 当用户加载论坛时,检查上次加载论坛的时间

  • 检查自上次查看论坛以来发布的所有帖子

  • 在包含字段(user_id,post_id)的表中将这些值输入数据库。

  • 当他们查看帖子时,会从数据库中删除该值



问题I我认为这是一个巨大的数据库流失。这似乎是低效率。我确信在字段中有数组的方法,但我不是真的很好的数组。



任何人都可以给我一个良好的数据库设计的指示,以及任何代码,它必须与它吗?这让我疯狂,因为我只是不能想到一个解决方案,这是好的和有效的服务器。



先感谢您的帮助和帮助, p>

James。

解决方案

这是一个很好的问题,



我的想法基本上是:


  1. 在主题表中创建一个名为 is_new 的新字段。此字段包含字符串形式的值列表,遵循某种模式。例如: 5 | 6 | 12 | 110 | 2 | 45 | 之间的每个值代表已阅读主题的用户ID。


  2. 跳转到论坛,同时获取返回主题列表,您将检查每个主题是否由该用户阅读,简单:




    • 使用 explode('|',$ row ['is_new']); 使用 is_new li>
    • 现在你有一个包含值的数组,只需要检查 in_array($ user ['id'],$ list_of_ids); / li>

  3. 如果 false ,请标记主题未读,否则标记,并将该用户的ID更新为 is_new 列表。


这种方法似乎不如原来的方法那么痛苦,因为它只检查比普通的更多,同时获取主题列表。

注意:,你不必担心这个问题因为 is_new 包含多个值,您只能使用它进行检查和更新,无需选择。



另外,或者,您可以检查主题是新的还是不使用时间比较。例如,如果一个主题持续4周,而用户不读它,那么即使它是未读的(它是有意义的,就像报纸一样)。



这种方法特别适用于很多论坛软件,因为它很快,更有意义。请记住,浏览器最初支持您确定读/未读主题,即如果主题的超链接的颜色被访问,它将被改变。现在,返回 Cookie 解决方案。我不担心用户删除其Cookie。这很少发生,用户不会因为阅读主题在删除cookie后转换未读而死。 / p>

很开放的主题不是吗?希望这有帮助(:


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 though:

How do I show a user if a post is new/unread or not.

Two solutions come into mind:

1) Cookies 2) Database

I don't want to use cookies because they can be deleted by the user and the firefox side of things means they are auto deleted. Either way, I don't want to use cookies.

The database is causing me a problem because I can't seem to get the database structure sorted in my head! The first solution I could think of was:

  • When a user loads the forums up, check the last time they loaded the forums up
  • Check all the posts have been made since they last viewed the forums
  • Enter those values into the database in a table with fields (user_id, post_id).
  • that value is then deleted from the database when they view the post

The problems I am thinking with this is it's a huge database drain. It seems SO inefficient. I'm sure there are methods with arrays in fields, but I'm not really that good with arrays.

Could anyone give me an indication of a good database design for this as well as any code that has to go with it? It's driving me crazy as I just can't think of a solution that's good and efficient with the server.

Thanks a lot in advance for your help and assistance,

James.

解决方案

This is somehow a good question, I've never experienced this before so I could only suggest you an idea in which I have no guarantee about its correctness.

My idea basically is:

  1. Create a new field, called is_new inside a topic table. This field contains a list of values in string form, following a certain pattern. For example: 5|6|12|110|2|45. Each value between | represents a user's ID, who has read the topic.

  2. Every time a user jumps into a forum, while fetching to return the list of topics, you will check if each topic is read by that user, simple by:

    • Explode the string in is_new using explode('|', $row['is_new']);
    • Now you have an array contain the values, just need to check in_array($user['id'], $list_of_ids);
  3. If false, mark the topic unread, otherwise mark it read and also update that user's ID into the is_new list.

This approach seems less 'painful' than your original approach, since it only checks further more than ordinary, and as simultaneously as you fetch the list of topics. I think it will affect a little bit more if you have heaps of users.

Note: you don't have to worry about the problem of normalization since is_new contains multiple values, you only use it to check and update, no selection required.

In addition, alternatively, you can check the topics are new or not using time comparison. For example, if a topic lasts for 4 weeks and a user doesn't read it, then it returns old even though it's unread (it makes sense doesn't it? Just like a newspaper). I think you will be able to do this, quite easy indeed.

This approach is particularly applied by quite a few forum software, since it is quick and makes more sense. Remember that the browsers initially support you with determining read/unread topics, i.e. the color of hyperlink to the topic will be changed if it's visited. Now it turns back to the Cookies solution. I wouldn't worry about users deleting their cookies. This happens rarely and the users won't die just because the read topics turn unread after they delete the cookies.

Quite an open-ended topic isn't it? Hope this helps (:

这篇关于自定义php论坛 - 显示新的/未读的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆