簡體   English   中英

codeigniter活動記錄“內部”聯接

[英]codeigniter active record 'inner' join

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

我需要幫助將其更改為活動記錄的codeigniter。

我試圖從兩個表中獲取等於id的值並將其加入。 但是當我嘗試這樣

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

它僅顯示通過id傳遞的第一個聯接表。

嘗試這個

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

默認情況下,其內部聯接

 $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