0

我有个问题。多个 Dj 正在我们的收音机上制作音乐,但我们想制定一个时间表,所以我们制作了很多关于 DJ 信息的专栏,但也在十二个不同的专栏中包含十二个日期时间戳。

问题是,我如何选择第一个即将到来的日期?或者我如何选择日期高于当前日期的第一列。以及以下的。

如果解决了这个问题,我在回显它时遇到了另一个问题,因为它下面的脚本如何知道我使用了哪个变量。

我使用了以下变量和列:$date1、$date2、$date3 等。

谢谢!

4

2 回答 2

0

通常,我会通过执行正常的 SELECT 语句但将结果限制为“1”并使用 WHERE 子句来获取日期,并确保结果按日期排序,从而从数据库中获取下一个(即将到来的)日期。

在下面的示例中,我从数据库中选择了下一个日期的记录,其中也可能包括今天本身。如果您不关心今天的记录,那么只需将选择命令中的“newtime”变量更改为“todaydate”。

$todaydate = date('Y-m-d');
$newdate = strtotime ( '-1 day' , strtotime ( $todaydate ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );

SELECT * FROM table WHERE date > '$newdate' ORDER BY table.`date`ASC LIMIT 1
于 2012-12-30T02:44:09.663 回答
0
SELECT *
FROM (
    SELECT dj, 'date1' whichdate, if (date1 >= now(), date1, null) nextdate
    union
    SELECT dj, 'date2' whichdate, if (date2 >= now(), date2, null) nextdate
    union
    SELECT dj, 'date3' whichdate, if (date3 >= now(), date3, null) nextdate
    union
    SELECT dj, 'date4' whichdate, if (date4 >= now(), date4, null) nextdate
    union
    SELECT dj, 'date5' whichdate, if (date5 >= now(), date5, null) nextdate
    union
    SELECT dj, 'date6' whichdate, if (date6 >= now(), date6, null) nextdate
    union
    SELECT dj, 'date7' whichdate, if (date7 >= now(), date7, null) nextdate
    union
    SELECT dj, 'date8' whichdate, if (date8 >= now(), date8, null) nextdate
    union
    SELECT dj, 'date9' whichdate, if (date9 >= now(), date9, null) nextdate
    union
    SELECT dj, 'date10' whichdate, if (date10 >= now(), date10, null) nextdate
    union
    SELECT dj, 'date11' whichdate, if (date11 >= now(), date11, null) nextdate
    union
    SELECT dj, 'date12' whichdate, if (date12 >= now(), date12, null) nextdate
)
WHERE nextdate IS NOT NULL
ORDER BY dj, nextdate
于 2012-12-30T06:44:53.670 回答