从多个表codeigniter中提取数据

时间:2016-08-06 03:51:39

标签: codeigniter

我试图使用左连接和where子句从3个表中获取数据,如果我加入两个表它显示记录但是当我加入第三个表时它不会拉记录不知道为什么

public function get_customer_detail_4_withdraw($customer_id) {

        $query = $this -> db -> select('*')
                             -> from('deposits')
                             -> where('deposits.customer_id', $customer_id)
                             -> join('customers', 'deposits.customer_id=customers.id', 'left')
                             -> where('withdraw_deposit.customer_id', $customer_id)
                             -> join('withdraw_deposit', 'withdraw_deposit.customer_id=deposits.customer_id', 'left')
                             -> get();
        return $query -> result();

    }

1 个答案:

答案 0 :(得分:0)

我认为你需要重新安排连接和位置。

例如:

public function get_customer_detail_4_withdraw($customer_id) {

    $query = $this -> db -> select('*')
                         -> from('deposits')
                         -> join('customers', 'deposits.customer_id=customers.id', 'left')
                         -> join('withdraw_deposit', 'withdraw_deposit.customer_id=deposits.customer_id', 'left')
                         -> where('deposits.customer_id', $customer_id)
                         -> where('withdraw_deposit.customer_id', $customer_id)
                         -> get();
    return $query -> result();

}
相关问题