join query in CodeIgniter [duplicate] join query in CodeIgniter [duplicate] codeigniter codeigniter

join query in CodeIgniter [duplicate]


Try with this:

$this->db->join('credentials', 'tblanswers.answerid = credentials.cid');

Or

$this->db->join('credentials', 'tblanswers.answerid = credentials.cid', 'inner');

And print the result to see if is what you want


What's the primary table you want to query? Well you can try this one, suggested that when using joins, you must specify an alias for each table:

 function result_getall(){    // if you want to query your primary data from the table 'tblanswers',    $this->db->select('a.*,b.*'); <-- select what you might want to select    $this->db->from('tblanswers a');    $this->db->join('credentials b', 'b.cid = a.answerid', 'left');     $query = $this->db->get();    return $query->result();    // if you want to query your primary data from the table 'credentials',    $this->db->select('a.*,b.*'); <-- select what you might want to select    $this->db->from('credentials a');    $this->db->join('tblanswers b', 'b.answerid = a.cid', 'left');     $query = $this->db->get();    return $query->result();}


Remove select() tag, as u need all terms.

U can modify code like

$this->db->join('credentials', 'tblanswers.answerid = credentials.cid', 'outer'); $query = $this->db->get('tblanswers');return $query->result();