Search code examples
phpmysqlcodeigniteractiverecordcodeigniter-2

What's wrong with this query in active record CodeIgniter 2?


I have some problem with active record in CodeIgniter 2.

SQL works perfectly:

SELECT c.title
     , c.post_status
     , d.data  
  FROM content c
  JOIN content_fields_data d
    ON c.id = d.item_id 
 WHERE c.full_tpl = 'page_doctor' 
   AND d.field_name = 'field_docid'

But when I'll try write this query in active record style, like this:

$this->db->select('c.title, c.post_status','cd.data', false);
$this->db->from('content as c');
$this->db->join('content_fields_data as cd', 'c.id = cd.item_id','left');
$this->db->where('c.full_tpl', 'page_doctor');
$this->db->where('cd.field_name', 'field_docid');

$allDatas = $this->db->get()->result_array();

I don't see in output cd.data.

What's I'm doing wrong?


Solution

  • By accident you split your list of columns to two method's arguments, it should be one string

    $this->db->select('c.title, c.post_status, cd.data', false);