我知道如何检索每个帖子的评论,但现在我正在尝试自己的系统'回复'。当有人回复时,我会在新评论中将评论ID存储为 reply_id 。
$sql = 'SELECT cid, cname, user_uid, reply_id,
published, content, avatar
FROM comments, users
WHERE report < 3 AND (uid = user_uid AND post_pid='.$id.')
OR ( user_uid ="_'.$id.'" AND post_pid='.$id.')';
此请求返回此评论列表:
Array
(
[0] => stdClass Object
(
[cid] => 101
[cname] => ramzan
[user_uid] => 1
[reply_id] => 100
[published] => 2013-12-08 01:44:56
[content] => why?
[avatar] => users/anonyme.png
)
[1] => stdClass Object
...
但我想得到这样的东西:
Array
(
[0] => stdClass Object
(
[cid] => 101
[cname] => ramzan
[user_uid] => 1
[reply_id] => array() // the reply if exist
[published] => 2013-12-08 01:44:56
[content] => why?
[avatar] => users/anonyme.png
)
也许这样做是个不错的主意,但我不知道怎么做!!!
答案 0 :(得分:0)
...SELECT field FROM table where ...
ORDER BY COALESCE (lvl1, lvl2, id ), lvl1, lvl2, id
...
谢谢,
祝你好运