Reputation: 2277
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
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
Reputation: 32532
mysql_query("SELECT * FROM files WHERE `user_name` = '{$_SESSION['username']}' ORDER BY `file_time` LIMIT $start, $per_page")
Upvotes: 3
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