作者:芸阁__907 | 来源:互联网 | 2023-10-09 20:52
只想在CODEIGNITER中使用1到3个表格,如何做到这一点在这个查询中,我只加入了一个表,我怎么能加入我的第3,第4表$this-db-select('*
只想在CODEIGNITER中使用1到3个表格,如何做到这一点
在这个查询中,我只加入了一个表,我怎么能加入我的第3,第4表
$this->db->select('*');
$this->db->from('table1');
$this->db->join('table1', 'table1.dep_id = table2.dep_id', 'table1.status= 1');
$this->db->limit(1);
$this->db->order_by("expiredate", "desc");
return $this->db->get()->result();
我的表结构如下
表格1
t1_id
t1_name
t2_id
t3_id
t4_id
表2
t2_id
t2_name
表3
t3_id
t3_name
表4
t4_id
t4_name
我怎样才能加入我的第3和第4
提前问候……
解决方法:
尝试这个我认为它的工作
$this->db->select('table1.*,table2.t2_name,table3.t3_name,table4.t4_name');
$this->db->from('table1','table2','table3','table4');
$this->db->join('table2', 'table1.t2_id= table2.t2_id');
$this->db->join('table3', 'table1.t3_id= table3.t3_id');
$this->db->join('table4', 'table1.t4_id= table4.t4_id');
return $this->db->get()->result();
或者你可以使用SQL查询来获得结果….
$this->db->query($sql)->result();