ORDER BY DESC与CURDATE();语句不在php mysql中工作

时间:2014-09-17 09:07:29

标签: php mysql sql sql-order-by

$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将起作用。

请帮忙!

4 个答案:

答案 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()