【发布时间】:2014-06-20 14:51:33
【问题描述】:
我正在开发一个类似于 Facebook 评论/论坛帖子的功能。
表结构是这样的:
Post
========
id
txtMsg
createDate
updateDate
isShow
userID
postID
User
=======
id
name
所以,这个表已经代表了帖子和评论。这意味着,如果是 post , postID 将为 null ,如果这是 reply ,则它具有父 postID。
我的目标是
按创建日期 (Desc) 获取用户的评论/帖子以及他们朋友的帖子顺序。
-
有一个字段调用 isShow,这意味着对于任何 isShow 为 0 的帖子,那么所有帖子和评论都不应包含在结果集中。
加入用户表获取用户名
我在 codeigniter 项目上工作,但这没关系,我可以转换语法 SQL 查询。非常感谢您提供任何帮助。
在我的预期结果中,我可以在我的界面中生成这样的输出
Comment-er name (comment date)
comment message
1st Reply-er name (1st reply date)
1st reply message
2nd Reply-er name (2nd reply date)
2nd reply message
.....
尝试这样的代码,但需要一些调整,其中 $facebookIDList 已经包含用户 ID 和用户的朋友 ID
$this->db->select('c.id as id, u.name as username, c.txtMsg as txtMsg, c.createDate as createDate, c.updateDate as updateDate, c.imageURL as imageURL, c.postID as postID, c.isShow as isShow');
$this->db->from('comment as c, user as u');
$this->db->where('u.id = c.userID');
$this->db->where('c.isShow = 1');
$this->db->where_in('c.userID', $facebookIDList);
$this->db->order_by('c.createDate', 'Desc');
【问题讨论】:
标签: php mysql sql database codeigniter