$ this-> db->在哪里使用它?

时间:2015-03-18 02:12:26

标签: database codeigniter

在这段代码中,我想从数据库中选择记录,其中employee_id_open和employee_id_close相同且与变量$employee_id相同

$employee_id = 1;
$between = 'between ' . $this->db->escape($this->params['start_date'] . ' 00:00:00').' and ' . $this->db->escape($this->params['end_date'] . ' 23:59:59');
        $this->db->select("registers.name as register_name, open_person.first_name as open_first_name, open_person.last_name as open_last_name,open_person.hourly_salary as hourly_salary, close_person.first_name as close_first_name, close_person.last_name as close_last_name, register_log.*, (register_log.close_amount - register_log.open_amount - register_log.cash_sales_amount) as difference");
        $this->db->from('register_log as register_log');
        $this->db->join('people as open_person', 'register_log.employee_id_open=open_person.person_id');
        $this->db->join('people as close_person', 'register_log.employee_id_close=close_person.person_id', 'left');
        $this->db->join('registers', 'registers.register_id = register_log.register_id');
        //------My modification - but this is not working. no records are selected with this query
        $this->db->where('open_person.person_id ', 'close_person.person_id');
        // I also tried this>>>  $this->db->where('open_person.person_id = ', 'close_person.person_id');
        //------/ My modifcation
        $this->db->where('register_log.shift_start ' . $between);
        $this->db->where('register_log.deleted ', 0);
        $this->db->where('registers.location_id', $location_id);

你能告诉我我做错了什么以及如何解决这个问题?

非常感谢任何帮助。 非常感谢

1 个答案:

答案 0 :(得分:0)

你可以使用$ this-> db-> last_query()转储最后一个查询sql语句。