简体   繁体   中英

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.

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.

尝试下面的事情

 $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. If you need the excact query please provide the details of tables pay and emp.

你可以用这个

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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