【问题标题】:Joining TAbles for count using Codeigniter使用 Codeigniter 加入 Tables 进行计数
【发布时间】:2018-12-08 01:41:38
【问题描述】:

这是我的数据库

branch               category_branch
---------------      ---------------
id_branch            id
category_id          public(1/0)
branch_name          category_name

这是我在模型上的简单功能

function count_branch_all()
{
    return $this->db
            ->count_all_results('branch');
}

我想计算 public = 1 的表分支上的数据

请帮帮我...

【问题讨论】:

    标签: sql codeigniter join


    【解决方案1】:

    您必须将分支表与 cateroty_branch 表连接起来,条件是:

    function count_branch_all()
    {
        $this->db->select('*');
        ->from('branch');
        ->join('category_branch','branch.category_id=category_branch.id', 'left');
        ->where('public',1);
        return = $this->db->count_all_results();
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-09
      • 1970-01-01
      • 2016-05-10
      • 1970-01-01
      • 2012-08-07
      • 2016-01-25
      • 1970-01-01
      • 2015-07-10
      • 1970-01-01
      相关资源
      最近更新 更多