我一直在寻找答案,但似乎无法弄清楚,所以我希望这里的人可以提供帮助。我只是想找出一种方法,只在一个页面上显示 XX 评论,允许这个过程嵌套/线程评论,当用户可能有超过 1,000 条评论时,不必在一页上显示所有评论。如果我尝试使用一个 mysql 查询而不是 2 个来执行此操作我必须这样做。
这是我的 MySQL 表(它是一个尚未发布的新表,因此我可以根据需要进行更改)
CREATE TABLE IF NOT EXISTS `comments_threaded` (
`id` bigint(255) NOT NULL AUTO_INCREMENT,
`toUid` bigint(255) NOT NULL,
`fromUid` bigint(255) NOT NULL,
`Pid` bigint(255) NOT NULL,
`Puid` bigint(255) NOT NULL,
`Pseen` int(2) NOT NULL,
`seen` int(2) NOT NULL,
`comment` text NOT NULL,
`tim` int(20) NOT NULL,
`Pip` varchar(30) NOT NULL,
PRIMARY KEY (`id`),
KEY `toUid` (`toUid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
id = 评论的 id 自动增加
toUid = 是针对哪个个人资料/用户的
fromUid = 评论来自谁
Pid = 父 id 的 id..
Puid = 父 id 的用户 id 编号
Pseen = 如果是父user has seen the comment
seen = if the toUid has seen the comment
comment = fromUid 留下的评论
tim = 留下的时间()
Pid = 人的 ip
无论如何,我正在尝试对用户个人资料发表评论,如果他们想回复他们,他们会在其中嵌套对上一个/父评论的回复。
我想将页面上的评论数量限制为 10 或 20,无论我觉得合适,这个数字还包括嵌套评论。
例如,如果我想在第 1 页上发表 10 条评论
comment 1
--comment 2 replied to comment 1
--comment 3 replied to comment 1
----comment 4 replied to comment 3
------comment 5 replied to comment 4
comment 6
--comment 7 replied to comment 6
--comment 8 replied to comment 6
comment 9
--comment 10 replied to comment 9
然后在第 2 页,如果第一条评论是对另一条评论的回复,它将从他们回复的原始父评论开始,如果仍然只能在该页面上保留 10 条评论,如果不是的话可以在顶部显示额外的评论,或者可能在底部显示第 1 页的额外评论。我不确定哪个会更容易。
comment 9
--comment 10 replied to comment 9
----comment 11 replied to comment 10
----comment 12 replied to comment 10
--comment 13 replied to comment 12
comment 13
comment 14
--comment 15 replied to comment 14
--comment 16 replied to comment 14
----comment 17 replied to comment 16
----comment 18 replied to comment 17
--comment 19 replied to comment 17
comment 20
我在想一个 MySQL IN 子句会这样做,但我得到一个错误..“试过 -
SELECT id, fromUid, Pseen, seen, comment, tim
FROM comments_threaded
WHERE toUid = '".mysql_real_escape_string($toUid)."'
OR Pid IN (
SELECT id, fromUid, Pseen, seen, comment, tim
FROM comments_threaded
WHERE toUid = '".mysql_real_escape_string($toUid)."'
)
LIMIT 10
并且得到
Operand should contain 1 column(s)
这是我以前从未见过的..
如果可以的话,感谢您的寻找和帮助!