繁体   English   中英

需要帮助我的论坛仪表板的 mySQL 查询

[英]Need help for mySQL query for my forum dashboard

我的论坛仪表板

我有 2 个表 forum_category 和 forum_topics。 问题是最新的帖子不准确......我不知道它的查询。

谁能帮我 ?

示例输出在图像上......我正在使用 codeigniter

  • category包含列 id,name,desc
  • topic包含id、subject、desc、date_posted 和posted_by 列

询问:

$select =   array(
            'forum_category.f_cat_name',
            'forum_category.f_cat_id',
            'forum_category.f_cat_desc',
            'forum_topic.topic_subject as last_posted',
            'max(forum_topic.date_posted) as last_date_posted',
            'max(forum_topic.posted_by) as last_posted_by',
            'count(forum_topic.topic_id) as total'
        );  
        $query=$this->db
    ->select($select)
    ->from('forum_category')
    ->where('f_cat_type',1)
        ->where('f_cat_status',1)

    ->join('forum_topic','forum_topic.f_cat_id = forum_category.f_cat_id','inner')
    ->group_by('forum_category.f_cat_id')
    ->get();
    return $query->result();

Join 子句应该在 where 子句之前。

尝试这个,

$query=$this->db
->select($select)
->from('forum_category')
->join('forum_topic','forum_topic.f_cat_id = forum_category.f_cat_id','inner')  
->where('f_cat_type',1)
->where('f_cat_status',1)
->group_by('forum_category.f_cat_id')
->get();
return $query->result();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM