【发布时间】:2012-06-07 22:00:27
【问题描述】:
我一直在寻找答案,但似乎无法弄清楚,所以我希望这里有人可以提供帮助。我只是想找出一种方法,只在一个页面上显示 XX cmets,允许嵌套/线程化 cmets 的过程,并且当用户可能拥有超过 1,000 个 cmets 时,不必在一页上显示所有 cmets。我正在尝试使用一个 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 = 如果父用户看过评论
看过 = 如果 toUid 看过评论
comment = fromUid
留下的评论
tim = 剩下的时间()
Pid = 人的 ip
不过,我正在尝试在用户个人资料中添加 cmets,如果他们想回复他们,他们会在其中嵌套对上一个/父评论的回复。
我想将页面上的 cmets 数量限制为 10 或 20,无论我觉得合适,这个数字还包括嵌套 cmets..
例如,如果我想在第 1 页上显示 10 个 cmets
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 个 cmets,如果不是最好在顶部显示额外的 cmets,或者在底部显示第 1 页上的额外 cmets。我不确定哪个会更容易。
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)
我以前从未见过..
如果可以的话,感谢您的寻找和帮助!
【问题讨论】:
标签: php mysql comments threaded-comments