1
votes
query('SELECT * FROM answers INNER JOIN questions 
      WHERE answers.answerId= questions.questionId AND answers.answerId IN (' . $id . ')')

I need help to change this to active record for codeigniter.

i tried to get the values which is equal to the id form the two tables and join it. but when i tried like this

$this->db->select("*"); $this->db->join("questions","questions.questionId = answers.answerId"); $this->db->where_in('answers.answerId',$id); $res = $this->db->get("answers"); 

It's only displaying the first joined table passed through the id.

2
Hi Kohli, Welcome to stackoverflow, please provide some explanation what is issue.WoodChopper
@WoodChopper i tried to get the values which is equal to the id form the two tables and join it. but when i tried like this $this->db->select("*"); $this->db->join("questions","questions.questionId = answers.answerId"); $this->db->where_in('answers.answerId',$id); $res = $this->db->get("answers"); It's only displaying the first joined table passed through the id.Kohli

2 Answers

0
votes

Try this

    $this->db->select('*');
    $this->db->from('answers'); 
    $this->db->join('questions','questions.questionId=answers.answerId');
    $this->db->where_in('answers.answerId',$id);
    $query=$this->db->get();
    $result=$query->result();
0
votes

By default, its inner join

 $this->db->select("*");
 $this->db->join("questions","questions.questionId = answers.answerId");
 $this->db->where_in('answers.answerId',$id);
 $res = $this->db->get("answers");