Search code examples
phpmysqlcodeigniterjoinquery-builder

How to implement a comma-separated JOIN query with CodeIgniter's query builder methods


I am trying to fetch data from the table which has some foreign keys by using CodeIgniter's active records, but I haven't gotten any results (or errors). Where am I going wrong with my model method below?

public function fetch_customer()
{
    $s = 'customer.stb_id';
    $w_array = array('set_top_box.stb_id' => $s );
    $customers = $this->db
        ->select('customer.c_name,customer.acc_no,customer.stb_id,set_top_box.stb_no,customer.mobile_no,customer.subscription_amount,customer.c_status')
        ->from('customer,set_top_box')
        ->where($w_array)
        ->get();
    return $customers->result();
}

Solution

  • Hello you can not add multiple table name in form () clause you use join() like this

    public function fetch_customer()
        {
            $s = 'customer.stb_id';
            $w_array = array('set_top_box.stb_id' => $s );
            $customers = $this->db->select('customer.c_name,customer.acc_no,customer.stb_id,set_top_box.stb_no,customer.mobile_no,customer.subscription_amount,customer.c_status')
                                  ->from('customer')
                                  ->join('set_top_box','here on clause ')  
                                  ->where($w_array)
                                  ->get();
                return $customers->result();
        }