CodeIgneitor查询构建器类,用于在多个条件下选择数据

时间:2017-04-26 12:09:33

标签: php codeigniter

我必须在我的代码中使用以下条件,但只有条件01和03正常工作。有人可以帮我吗?我的代码是:

public function errorTime(){

    $fromDate=date("Y-m-d", strtotime($_SESSION['FromDate']));
    $toDate=date("Y-m-d", strtotime($_SESSION['ToDate']));
    $this->db->select('*');
  

条件01

    $where = "(TimeStatus='Yes' AND CheckIn='00:00:00' OR TimeStatus='Yes' AND CheckOut='00:00:00')";
    $this->db->where($where);
  

条件#02

    $this->db->where('TotalTime <', 0);
  

条件#03

    $this->db->where('Date >=', $fromDate);
    $this->db->where('Date <=', $toDate);

    $this->db->from('tb_time');
    $query=$this->db->get();

    return $query->num_rows();

}

注意:TotalTime - &gt;数据类型:Float

1 个答案:

答案 0 :(得分:0)

最后,我找到了解决方案:

public function errorTime(){

    $fromDate = date("Y-m-d", strtotime($_SESSION['FromDate']));
    $toDate = date("Y-m-d", strtotime($_SESSION['ToDate']));
    $this->db->select('*');
    $where = "(TimeStatus='Yes' AND CheckIn='00:00:00' OR TimeStatus='Yes' AND CheckOut='00:00:00' OR CheckOut <= CheckIn)";
    $this->db->where($where);
    $this->db->where('Date >=', $fromDate);
    $this->db->where('Date <=', $toDate);
    $this->db->from('tb_time');
    $query=$this->db->get();
    return $num_rows=$query->num_rows();
}