Jump to content

Last 10 Records


supertrucker

Recommended Posts

Can anybody help me code out some PHP that will return just the last 10 rows/records of a table? I'm stumped!Thanks in advance,Supertrucker :)

Link to comment
Share on other sites

<?php$con = mysql_connect("host", "user", "pass") or die("Could not connect to database because ".mysql_error());if(!mysql_select_db("database",$con)) die("Could not connect to database because ".mysql_error();$query = mysql("SELECT * FROM table ORDER BY unique_field DESC LIMIT 10");while ($rows=mysql_fetch_array($query)) {print $rows['field_name'].'<br />'.$rows['another_field'].'<br /><br />';}?>i've not tested it, but it should work. Just replace host, user, pass and database to connect. Then obviouslly change the values in the query.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...