strtotime / array中的AND OR语法

时间:2017-11-13 04:24:03

标签: php arrays strtotime

我开发了一个程序,如果数据超过1天或者不到1天就看不到数据,因此您只能看到今日数据,明天数据和昨日数据。

我尝试在我的数组和strtotime中使用or /和语法,但是它没有用。

我试过了:

   $date = date('Y-m-d');
    $date1 = date('Y-m-d',strtotime("-1 days"));
    $date2 = date('Y-m-d',strtotime("+1 days"));

    $query = $this->db->get_where('info',array(dates => $date2 or $date or $date1)

);

我也试过这个:

$date = date('Y-m-d');
$date1 = date('Y-m-d',strtotime("-1 days"));
$date2 = date('Y-m-d',strtotime("+1 days"));
$datefix = $date or $date1 or $date2;

$query = $this->db->get_where('info',array(dates => $datefix));

两者都不起作用。我在ARRAY或STRTOTIME中搜索如何使用OR和AND语法,但我无法找到它。谁能帮我这个?很少得到帮助!

2 个答案:

答案 0 :(得分:1)

试试这个

$this->db->where('dates <=', $date1);
$this->db->where('dates >=', $date2);
$query = $this->db->get('info');

$this->db->where('dates', $date);
$this->db->where('dates', $date1);
$this->db->where('dates', $date2);
$query = $this->db->get('info');

答案 1 :(得分:1)

首先,您必须检查查询的语法。因为这是完全错误的。使用BETWEEN

SELECT *
FROM `TABLENAME`
WHERE (dates BETWEEN '$date1' AND '$date2')

我希望它有帮助!!!!