sushibrain
sushibrain

Reputation: 2780

Select from table where the date is later then today

So I'm busy on a schedule system, and since my client works in the tech business, I wanted to make a table listing 5 upcoming productions, based on the date.

The initial way was kinda stupid:

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

As said, pretty stupid, then on stackoverflow, I found a piece of code that made sense to me:

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

But as soon as I tried that, the following error popped up:

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

So how do I do this? I've asked several people, and they all don't know..

So how do I select values from a table where the date is later then today?

Thanks

Upvotes: 0

Views: 149

Answers (2)

jogesh_pi
jogesh_pi

Reputation: 9782

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

Upvotes: 1

user1897253
user1897253

Reputation:

ORDER BY goes before LIMIT

Check the whole syntax here: MySQL Select Syntax

Upvotes: 1

Related Questions