在PHP Codeignter中结合两个where子句查询,一个与DATE FORMAT一起使用

时间:2019-02-21 10:39:56

标签: php codeigniter mysqli

我有这两个where子句从表中选择数据。我想将两者合并为一个。当我添加AND时,它没有输出。如果我单独使用它,效果很好。...但是我想同时运行两个where条件

$this->db->where("(DATE_FORMAT(from_date,'%m') = '$m' AND DATE_FORMAT(from_date,'%Y') = '$y')OR (DATE_FORMAT(to_date,'%m') = '$m' AND DATE_FORMAT(to_date,'%Y') = '$y' )");
$this->db->where("resource","$e");

$this->db->order_by("status","desc");

1 个答案:

答案 0 :(得分:0)

尝试一下

$where = "((DATE_FORMAT(from_date,'%m') = '$m' AND DATE_FORMAT(from_date,'%Y') = '$y') OR (DATE_FORMAT(to_date,'%m') = '$m' AND DATE_FORMAT(to_date,'%Y') = '$y')) AND 'resource' = '$e'";
$this->db->where($where);
$this->db->order_by("status","desc");