Order a MySQL result by Date and Time in PHP
$datos = mysql_query("SELECT * FROM usuarios
LIMIT 0, 30 "开发者_运维技巧);
Who is a simple MySQL query in php, but i need the result organized by date and time. There is a field in my table who has this value (automatic inserted when the user sing up in my page). So the table is something like this:
Id Name DT
1 Domingo 2010-04-26 23:00:00
2 Cesar 2010-04-25 12:00:00
3 Nataly 2010-04-26 08:00:00
DT is a "datetime" field. How can i get the result order by new to old? Thanks!
Use the ORDER BY
clause to order the result set. Simply specify the column and ASC
for ascending or DESC
for descending.
SELECT * FROM `usuarios`
ORDER BY `DT` DESC
LIMIT 0, 30
Not looking for points as this doesn't answer your question specifically but I think it would be very beneficial for you to check out the tutorials here:
http://www.w3schools.com/sql/default.asp
They are well written and easy to understand and will send you on your way to becoming a learned student of web programming technologies.
精彩评论