tags:

views:

26

answers:

2

Hi, i have this code:

$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!

+3  A: 

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
Marcus Adams
quote the column name as well - it makes everyting easier to read, and is a nice habit :)
gnud
@gnud, I agree. Done and thanks.
Marcus Adams
A: 

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.

webbiedave