您的帖子不是很清楚,我不明白您在表主题中是否也发布了该主题并回复了该主题。
在这种情况下,我认为这不是好方法,您应该将帖子与主题数据分开。让我解释。
论坛由以下人员组成:
// MAIN PAGE, showing avaible forums
// |
// SPECIFIC FORUM, that show the threads (or topics) inside
// |
// POSTS that show part of the post related to that thread.
//
// USER_CP -------------- ADMIN_CP
我们至少需要 4 个表(我不考虑 admin_cp)。这些是:
// TOPICS:
// +---------------+---------+-------------+----------+----------+----------------+
// | ID, p.k. a.i. | TITLE | SUB_TITLE | AUTHOR | CLOSED | PARENT FORUM |
// +---------------+---------+-------------+----------+----------+----------------+
//
// These are very few basic field for the table. No reference about the posts here.
//
//
// FORUMS:
// +---------------+---------+-------------+--------------+
// | ID, p.k. a.i. | TITLE | SUB_TITLE | VISIBILITY |
// +---------------+---------+-------------+--------------+
//
// Almost clear, visibility is a value to determine if the forum is private (such are
// forums like: "Moderator rooms" or "Admin stuff"), protected (i.e. for non registered
// users, or if the forum is public.
//
//
// POSTS:
// +---------------+----------+-------+-----------+--------+---------+-------+- - -
// | ID, p.k. a.i. | TOPIC_ID | TITLE | SUB_TITLE | AUTHOR | MESSAGE | VOTES | ...
// +---------------+----------+-------+-----------+--------+---------+-------+- - -
//
// In Votes you have a integer number (positive o negative, no matter) with the total
// of the votes for this post (not useful if you fully use the table like).
//
// REPLIES
// +---------------+----------+---------+--------+---------+
// | ID, p.k. a.i. | TOPIC_ID | POST_ID | AUTHOR | MESSAGE |
// +---------------+----------+---------+--------+---------+
//
//
// USERS
// +---------------+------+------+------------+------+---------+- - - - -
// | ID, p.k. a.i. | NICK | PASS | PRIVILEGES | NAME | SURNAME | ETC..
// +---------------+------+------+------------+------+---------+- - - - -
//
// Privileges determinate if a user is admin, mod, super_mod or simple user
//
//
// LIKES
// +---------------+---------+---------+----------+----------+---------+------+
// | ID, p.k. a.i. | USER_ID | POST_ID | TOPIC_ID | REPLY_ID | UP_DOWN | DATE |
// +---------------+---------+---------+----------+----------+---------+------+
在我看来,这是您应该使用的结构。
主页,显示所有论坛:
- 读取用户的权限
- 从表格中读取论坛数据
WHERE visibility >= user_privileges
- 用适当的链接使每个论坛充满活力。
论坛页面,显示所有主题(和版主):
- 阅读表格中的主题
WHERE parent_forum = forum_id
- 阅读本论坛的版主
- 用适当的链接引人入胜的主题
- 在页面底部显示主持人。
主题页面,显示所有消息。
- 从表中读取 topi 数据。
- 话题也是第一条消息!
- 阅读表格中的帖子
WHERE topic_id = current_topic_id
- 对于从“LIKES”表中读取的每个帖子
WHERE post_id = selected_post
- 合计所有选票
- 将帖子放在适当的页面和适当的投票中。
用户页面:
- 读取所有数据,
WHERE id = user_id_that_want
- 从“喜欢”中读取
WHERE user_id = actual_user
- 您拥有用户发送的所有喜欢/不喜欢的内容。做你想做的事。
- 幻想
使用此表结构,您还可以使用 StackOverflow 类似的方式来考虑投票,即投票者的 UPvote 为 0,但投票者的 downvote 为 -1。对于每个帖子,您可以仅使用 post_id 从类似表中读取,因此您知道该帖子有多少票(上下),这样您还可以对帖子创建者进行投票 +10,对帖子进行投票 -5创造者。
只有一张喜欢的额外桌子。
你可以有:
- 对某个主题进行投票
- 对帖子投票
- 对答复投票
- 该主题的总票数(回复+帖子+主题)。
插入主题时,您将添加:
user_id
topic_id = topic id
post_id = -1 (this is not a post, is the topic!)
repl
y_id = -1(如上)
当您插入帖子时:
user_id
topic_id = current topic
post_id = post_id
reply_id = -1 (this is not a a reply)
当您插入回复时
user_id
topic_id = current topic
post_id = current post
reply_id = the reply id.
这不会有身份问题的问题。因为三者是分开的。
如果您要求获得特定主题和特定帖子的所有答案,您将添加:
WHERE topic_id = current, post_id = current
如果你需要一个主题的回复,只需输入 post_id = -1
等等。身份证没有问题!
我想我已经解释了几乎所有。有任何问题,问!编辑:这里和那里的东西