1

我在codeigniter的一个论坛上工作,我想显示一个类别中有多少个Thred,但我的问题是它只显示已经发布的类别。

我想显示所有类别,尽管其中没有帖子。我怎样才能做到这一点 ?。

这是我的模型文件

//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();

}
4

1 回答 1

0

当您加入 forumThread 时,您将消除结果集中没有线程的记录。离开加入它而不是离开那些。

$this->db->join('forumThread', 'forumThread.fk_forumCategory = forumCategory.id', 'left');

更多细节在这里:http ://codeigniter.com/user_guide/database/active_record.html

于 2011-10-13T14:02:04.170 回答