1

我正在做一个项目,我必须从数据库中选择所有日期为昨天、今天和明天的条目。日期作为时间戳存储在数据库中。

到目前为止我有这个 PHP 代码

$hour = 12;
$today = strtotime("$hour:00:00");
$yesterday = strtotime('-1 day', $today);
$tomorrow = strtotime('+2 day', $today);
$today = get_date($today,"timestamp");

$result = $DB->query("SELECT product_id FROM " . DB_PREFIX . "expiry WHERE expiry_date BETWEEN $yesterday AND $tomorrow");

它不工作。请帮忙。

4

1 回答 1

1

试试这个

 $tomorrow = strtotime('+1 day', $today);

和 th sql 更改为此

   BETWEEN '".$yesterday."' AND '".$tomorrow."'

并确保

   `" . DB_PREFIX . "expiry` 

不是那样的

  `" . DB_PREFIX . "_expiry`
                    ^---------------did have this or something else like -
于 2012-12-31T19:47:55.817 回答