从表中选择日期晚于今天的表

时间:2015-01-17 11:31:02

标签: php mysql date

所以我忙于一个日程安排系统,而且由于我的客户在科技行业工作,我想根据日期制作一个列出5个即将开始的作品的表。

最初的方式有点愚蠢:

$date = date('d-m-Y'); SELECT id, name, date, location FROM productions WHERE date = > :date

如上所述,非常愚蠢,然后在stackoverflow上,我发现了一段对我有意义的代码:

SELECT id, name, date, location FROM productions WHERE date >= CURRENT_DATE LIMIT 5 ORDER BY date

但是一旦我尝试了,就会弹出以下错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY date' at line 1' in C:\xampp2\htdocs\public\planning.tpl:341 Stack trace: #0 C:\xampp2\htdocs\public\planning.tpl(341): PDO->prepare('SELECT id, name...') #1 C:\xampp2\htdocs\application\classes\class.template.php(61): include('C:\\xampp2\\htdoc...') #2 C:\xampp2\htdocs\application\classes\class.template.php(70): Template->getPage('planning') #3 C:\xampp2\htdocs\index.php(8): Template->render('planning') #4 {main} thrown in C:\xampp2\htdocs\public\planning.tpl on line 341

那我该怎么做?我问了几个人,他们都不知道......

那么如何从日期晚于今天的表中选择值呢?

由于

2 个答案:

答案 0 :(得分:2)

SELECT id, name, `date`, location FROM productions 
    WHERE date(`date`) >= CURRENT_DATE ORDER BY date(`date`) LIMIT 5 

答案 1 :(得分:1)

ORDER BYLIMIT

之前

检查整个语法:MySQL Select Syntax