如果日期是今天,则更改的SQL查询

时间:2011-11-28 17:31:25

标签: mysql

我无法决定如何从mysql数据库中获取最新的剧集ID。

我需要的是抓住过去最近的air_date,但如果这一集正在播出,那么归还这个。我的代码不起作用,我想我错过了一些东西。如果有人有任何建议如何实现这一点,我将不胜感激:

$today = mktime(0, 0, 0);

"SELECT `id` FROM `hm_episodes_main`
WHERE `show_id` = '{$iShowId}'
AND `episode_voting` = 'Yes'
AND `air_date` < '{$today}'
ORDER BY `air_date` DESC"

2 个答案:

答案 0 :(得分:1)

我认为您可能只需要修改现有查询以包含当前日期:

AND air_date &lt; = '{$ today}'

答案 1 :(得分:0)

如果我理解正确,air_date是一个纪元时间戳。怎么样:

   SELECT `id`
     FROM `hm_episodes_main`
    WHERE `show_id` = ?                  -- plug $iShowId in here
          AND
          `episode_voting` = 'YES'
          AND
          `air_date` <= UNIX_TIMESTAMP() -- no need for mktime()
 ORDER BY `air_date` DESC
    LIMIT 1;
相关问题