简体   繁体   English

codeigniter活动记录“内部”联接

[英]codeigniter active record 'inner' join

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. 我需要帮助将其更改为活动记录的codeigniter。

i tried to get the values which is equal to the id form the two tables and join it. 我试图从两个表中获取等于id的值并将其加入。 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. 它仅显示通过id传递的第一个联接表。

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();

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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM