[edit]: I'm terribly sorry for my timing on asking this question. I've just discovered that you can use the command
"ORDER BY `table`.`table_col` DESC"
to order your results from a MySQL table.
I am working on creating forum and I am using ajax to get results from a database table. I would like to order these results before I display them on the page, sorted by a timestamp of the current day of the month.
the day for each post is a two digit number in my MySQL table i.e. 06
for post one, 09
for post two, 21
for post 3
I know how to write the script to sort these, but I would like to know if there is an easier way.
Can I simply set the table in my phpMyAdmin to keep each post sorted in order from least to greatest on the value of the day column?
Indexes and Keys have an order, and often selecting from a table gives results in the order of the index/key relevant to the query.
That, however, is not always the case.
In SQL, no matter what you do to the table, the result set can come out in a completely different order.
For that reason, the only way to guarantee the order of the results is to specify an ORDER BY
in the query.