0

我有一个查询可以为学生分配家庭作业。我想始终显示小于或等于今天日期的所有内容,这很好并且已经完成,但是我如何在 PHP 或 MySQL 中添加一个规定,在上午 8:30 之后显示今天的事件,同时仍然显示今天之前的所有内容时间。

试图阻止学生在上学前看到他们的作业。

        //Get & Display the Homework
    $getTopics = mysql_query("SELECT topicId, categoryId, topicName, assignmentDate FROM forumTopics WHERE categoryId = '".$forumId."' AND hidden = '0' and assignmentDate <= '".$today."' ORDER BY createdDate DESC") or die("Cannot get forum topics: " . mysql_error());
4

1 回答 1

2

你的 SQL 是:

SELECT topicId, categoryId, topicName, assignmentDate
FROM forumTopics
WHERE categoryId = '".$forumId."' AND hidden = '0' and assignmentDate <= '".$today."'
ORDER BY createdDate DESC;

要在今天上午 8:30 之后进行此节目:

SELECT topicId, categoryId, topicName, assignmentDate
FROM forumTopics
WHERE categoryId = '".$forumId."' AND hidden = '0' and
      (assignmentDate < '".$today."' or assigmentDate = '".$today."' and time('".today."') >= '08:30:00'
ORDER BY createdDate DESC;

这是假设您的变量$today同时具有日期和时间。否则,只需使用now()和/或CURDATE()和/或CURTIME()

于 2013-09-03T02:25:07.373 回答