PHP / mySQL查询选择日期(“N”)加1天

时间:2015-05-05 11:21:00

标签: php mysql sql

我有以下PHP脚本:

$day = date("N");
$query_board = "SELECT day, time, timefromto, type, event, title, location, description, `until`, endtime FROM schedule WHERE `until` >= '$server_time' AND day LIKE '%$day%' ORDER BY `time` ASC";

这在whatsondv.co.uk显示如此:
page image

我想创建另一个页面,显示第二天(即明天)的结果。因此,如果当天为2(星期二),那么3只会出现day的结果。

这是否需要更改$day或其他内容的定义?

2 个答案:

答案 0 :(得分:0)

您可以使用准备好的声明:

$pdo = new PDO('mysql:dbname=' . $database . ';host=' . $host, $user, $password);
$query = $pdo->prepare('SELECT day, time, timefromto, type, event, title, location, description, `until`, endtime FROM schedule WHERE `until` >= :server_time AND day LIKE :day ORDER BY `time` ASC')
$query->execute(
  array(
    ':server_time' => $server_time,
    ':day' => $day
  )
);

http://php.net/manual/en/pdo.prepare.php

http://php.net/manual/en/pdo.construct.php

答案 1 :(得分:0)

更简单的方法:添加另一列列出' day'值减1(或在7的情况下,返回1)。然后使用:

$day = date("N");
$query_board = "SELECT tmrw, time, timefromto, type, event, title, location, description, `until`, endtime FROM schedule WHERE `until` >= '$server_time' AND tmrw LIKE '%$day%' ORDER BY `time` ASC";

这很有效。