$stmt = $db->query('SELECT postID, postTitle, postDate, postStatus, date_accepted FROM blog_posts WHERE postStatus = "pending" AND DATE(`postDate`) = CURDATE(); ORDER BY postDate DESC');
我有一个简单的SQL语句,它显示待处理的记录并通过DESC对它们进行排序,但它不起作用。但是,如果我删除“AND DATE(postDate
)= CURDATE();”声明DESC将起作用。
请帮忙!
答案 0 :(得分:2)
;
应该没有CURDATE()
。
$stmt = $db->query('SELECT postID, postTitle, postDate, postStatus, date_accepted FROM blog_posts WHERE postStatus = "pending" AND DATE(`postDate`) = CURDATE() ORDER BY postDate DESC');
答案 1 :(得分:1)
在CURDATE()
之后删除分号,分号是查询的结尾。
$stmt = $db->query('SELECT postID, postTitle, postDate, postStatus, date_accepted
FROM blog_posts WHERE postStatus = "pending"
AND DATE(`postDate`) = CURDATE()
ORDER BY postDate DESC');
答案 2 :(得分:0)
不需要的分号:
$stmt = $db->query('SELECT postID, postTitle, postDate, postStatus, date_accepted FROM blog_posts WHERE postStatus = "pending" AND DATE(`postDate`) = CURDATE(); ORDER BY postDate DESC');
// ^
答案 3 :(得分:0)
从CURDATE();
$stmt = $db->query('SELECT postID, postTitle, postDate, postStatus, date_accepted FROM blog_posts WHERE postStatus = "pending" AND DATE(`postDate`) = CURDATE() ORDER BY postDate DESC');
或者您也可以{/ 1}}使用此
date()