Dymond
Dymond

Reputation: 2277

order by date sql

Im trying to order a table by date, but get this error.

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 'WHERE user_name = 'felipe' LIMIT 0, 5' at line 1

If i delete the ORDER BY file_time it works properly ..

Any ideas ?

mysql_query("SELECT * FROM files ORDER BY `file_time` WHERE `user_name` = '{$_SESSION['username']}' LIMIT $start, $per_page")

Upvotes: 0

Views: 108

Answers (3)

Eric
Eric

Reputation: 2231

I believe your issue is your positioning on your ORDER BY. Try this:

SELECT * FROM files WHERE `user_name` = '{$_SESSION['username']}' ORDER BY `file_time` LIMIT $start, $per_page

Upvotes: 2

CrayonViolent
CrayonViolent

Reputation: 32532

mysql_query("SELECT * FROM files WHERE `user_name` = '{$_SESSION['username']}' ORDER BY `file_time` LIMIT $start, $per_page")

Upvotes: 3

libjup
libjup

Reputation: 4089

the order of your query is mixed:

mysql_query("SELECT * FROM files ORDER BY `file_time` WHERE `user_name` = '{$_SESSION['username']}' LIMIT $start, $per_page")

should be

mysql_query("SELECT * FROM files  WHERE `user_name` = '{$_SESSION['username']}' ORDER BY `file_time` LIMIT $start, $per_page")

Upvotes: 2

Related Questions