【问题标题】:Joining more that 2 tables in codeigniter with no common fields在没有公共字段的codeigniter中加入超过2个表
【发布时间】:2013-08-01 03:43:52
【问题描述】:

我有 3 张桌子,我想加入它们。如果这三个有一个领域彼此相似,那将很容易。问题是,table1 和 table2 有一个相似的字段,table2 和 table3 有另一个相似的字段,但是根本没有相似的字段可以连接 table1 和 table3。我尝试使用下面的代码加入他们,但它不起作用。我收到一个错误,字段“branch_name”未定义:

    $this->db->select('r.*,                          
                       b.id as branch_id,                           
                       b.name as branch_name');
    $this->db->join('users_branches AS ub', 'ub.user_id = r.user_id');
    $this->db->join('branches AS b', 'b.id = ub.branch_id');

    $this->db->where('payroll_period_id',$payroll_period_id);        
    return $this->db->get('dtr r');

有什么解决办法吗?

【问题讨论】:

    标签: php codeigniter jointable


    【解决方案1】:

    尝试在控制器中输入$this->output->enable_profiler(TRUE) 以查看已执行的 SQL。这样更容易排除故障。我通常会复制执行的 SQL 并在 MySQL 客户端中对其进行故障排除,看看出了什么问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多