Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在codeignator的get_where子句中连接两个表数据_Php_Mysql_Codeigniter - Fatal编程技术网

Php 如何在codeignator的get_where子句中连接两个表数据

Php 如何在codeignator的get_where子句中连接两个表数据,php,mysql,codeigniter,Php,Mysql,Codeigniter,我想在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));

我想在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));
        }
目前它正在从支付表中获取数据。我想做的是同时检查“emp”表中的“状态”字段是否为“活动”。我想将其加入$q。

试试下面的事情

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

你可以试试下面的

$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');
这里我假设您是通过员工id连接两个表。 如果您需要EXACT查询,请提供pay和emp表的详细信息。

您可以使用此

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