Return the latest 10 records from a mysql query [closed]

I’m assuming your table has an id column as the primary key with auto increment.

In which case, you need to add an ORDER BY and LIMIT to your query.

$q = mysql_query("SELECT name from films WHERE name LIKE '$name' ORDER BY id DESC LIMIT 10") or die(mysql_error());

ORDER BY id DESC will make your query put the latest records first.

LIMIT 10 will ensure that you only grab 10 records.

Leave a Comment