codeigniter 显示一个类别中有多少个线程
我在 codeigniter 的论坛上工作,我想显示一个类别中有多少个线程,但我的问题是它只显示已经发布的类别。
我想显示所有类别,尽管没有其中的帖子。 我该怎么做?
这是我的模型文件
//Load the category list to the forum frontpage
function loadCategoryList() {
$this->db->select('forumCategory.id as categoryID, category, description, COUNT(forumThread.id) as threadID');
$this->db->where('forumCategory.approved', 'yes');
$this->db->join('forumThread', 'forumThread.fk_forumCategory = forumCategory.id');
$this->db->group_by('categoryID');
$loadCategory = $this->db->get('forumCategory');
return $loadCategory->result();
}
im working on a forum in codeigniter and i want to show how many Threds there is in a category, but my problem is that it only shows the categorys that allready have been posted in.
and i want to show ALL the category although there is no posts in it.
how can i do that ?.
here is my model file
//Load the category list to the forum frontpage
function loadCategoryList() {
$this->db->select('forumCategory.id as categoryID, category, description, COUNT(forumThread.id) as threadID');
$this->db->where('forumCategory.approved', 'yes');
$this->db->join('forumThread', 'forumThread.fk_forumCategory = forumCategory.id');
$this->db->group_by('categoryID');
$loadCategory = $this->db->get('forumCategory');
return $loadCategory->result();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您加入forumThread 时,您将消除结果集中没有线程的记录。左加入它而不是保留它们。
更多详细信息请参见:http://codeigniter.com/user_guide/数据库/active_record.html
When you join forumThread, you are eliminating records in your result set that don't have threads. Left join it instead to leave those in.
More details here: http://codeigniter.com/user_guide/database/active_record.html