我已经寻找了一段时间,但似乎找不到答案,所以我希望这里有人能帮上忙。我只是想找出一种方法,只在一个页面上显示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 =父用户是否已看到评论
seen =如果toUid已看到该注释
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)我以前从未见过..。
如果可以的话,感谢您的关注和帮助!
发布于 2012-06-07 14:45:02
如果在IN()中使用子查询,则该子查询必须选择1列,且只能选择1列。你的选择是6。
此外,对于这种嵌套内容,您可能需要考虑使用嵌套集合模型。
https://stackoverflow.com/questions/10926701
复制相似问题