简体   繁体   English

如何在Codeigneitor的get_where子句中联接两个表数据

[英]How to join two tables data in get_where clause in Codeigneitor

i want to join two tables in get_where clause.how can i do that?currently i have following code. 我想在get_where子句中加入两个表。我该怎么办?目前我有以下代码。

if ($dep == "0") {
            $q = $this->db->get_where('pay', array("date" => $date));
        } else {
            $q = $this->db->get_where('pay', array("date" => $date, "dep" => $dep));
        }

currently its getting data from pay table.what i want to do is at same time to check "status" field is "Active" in 'emp' table.i want to join that to $q. 当前它从薪水表中获取数据。我想做的是同时检查“ emp”表中的“状态”字段是否为“活动”。我想将其加入$ q。

尝试下面的事情

 $q = $this->db->join('emp e','e.id = p.emp_id')->get_where('pay p', array("p.date" => $date,"e.status"=>"Active"));

You may Please try the following. 您可以尝试以下方法。

$this->db->select('*');
$this->db->from('pay');
$this->db->join('emp', 'emp.id = pay.empid');
$this->db->where('pay.date',$date);
$this->db->where('emp.status','active');

Here i am assuming that you are joining 2 tables by employee id. 在这里,我假设您要按员工ID加入2个表。 If you need the excact query please provide the details of tables pay and emp. 如果您需要查询,请提供表pay和emp的详细信息。

你可以用这个

 $q = $this->db->join('emp','emp.id = pay.emp_id')->get_where('pay', array("pay.date" => $date,"emp.status"=>"Active"));

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

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