对单独的评论区域进行编码的有效方法是什么?
我意识到这是一个抽象的问题,有几个答案,但我不知道从哪里开始。我想为我的每篇博客文章都有一个单独的评论区。每次更新代码以包含最新条目时,是否应该手动为每个条目的注释设置不同的表?
I realize this is somewhat of an abstract question that has several answers, but I am at a loss as to where to begin. I want to have a separate comments area for each of my blog posts. Should I just set up a different table for the comments for each entry manually every time I update the code to include the latest entry?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为评论创建一个新表,其结构类似于(当然您可以根据需要自定义它):
author_id 链接到登录用户的用户表,0 表示匿名用户。我希望其他一切都应该是不言自明的。
Create a new table for the comments with a structure similar to (of course you can customize it to your needs):
The author_id is linked to the users table for logged in users, 0 for an anonymous user. Everything else should be self explanatory I hope.
我不确定你的意思是什么......但听起来你想针对每篇文章发表评论。如果是这种情况,只需在评论表中为“post_id”或类似的内容创建一个字段即可。然后在每个帖子页面上只需使用 SELECT 语句来获取该特定 post_id 的评论。
I'm not sure what you're quite getting at... but it sounds like you want to have comments specific to each post. If that's the case, just simply make a field in the comments table for "post_id" or something similar. Then on each post page just use a SELECT statement to grab comments for that particular post_id.
只需使用一个数据库表将帖子 ID 存储在其中一个字段中即可。类似于以下内容:
然后您可以简单地查询帖子评论,如下所示:
当然,请务必清理上述查询,因为您不希望任何人传递他们对
$pid 的值的感觉
。您需要确保它是一个数字,并且只是一个数字。Simply have a database table storing the post ID in one of the fields. Something similar to the following:
Then you can simply query for post comments like thus:
Of course, be sure to sanitize the above query, as you don't want any one passing what they feel like for the value of
$pid
. You need to make sure it's a number, and a number only.