codeigniter 显示一个类别中有多少个线程

发布于 2024-12-09 09:58:46 字数 642 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮光之海 2024-12-16 09:58:46

当您加入forumThread 时,您将消除结果集中没有线程的记录。左加入它而不是保留它们。

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

更多详细信息请参见: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.

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

More details here: http://codeigniter.com/user_guide/database/active_record.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文