微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 在此查询多表中加入codeigniter表

只想在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();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐