PHP and MySQL: Order by most recent date and limit 10 PHP and MySQL: Order by most recent date and limit 10 php php

PHP and MySQL: Order by most recent date and limit 10


This should do it :

$result = mysql_query("SELECT * FROM notes WHERE note_author_id='$u_id' ORDER BY date_time DESC LIMIT 0, 10");


use:

SELECT * FROM notes WHERE note_author_id='$u_id' ORDER BY date_time DESC LIMIT 10

DESC : descending order ( from newest to oldest )LIMIT 10: first 10 records found.


Try

$result = mysql_query("SELECT * FROM notes WHERE note_author_id='$u_id' ORDER BY date_time DESC LIMIT 10");

For a more detailed explanation on ORDER and LIMIT, visit the MySQL doc's articles about sorting rows and the basic select syntax (look for a bullet describing LIMIT).