我有一个问题,就是给学生拉作业。我希望总是显示小于或等于今天日期的所有内容,这很好,但是我如何在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());发布于 2013-09-03 10:25:07
您的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()即可。
https://stackoverflow.com/questions/18583143
复制相似问题