supertrucker Posted January 23, 2007 Share Posted January 23, 2007 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 More sharing options...
xpriens Posted January 23, 2007 Share Posted January 23, 2007 Not sure of PHP....but in SQL u can get those by giving the top clauseSelect top 10 from Table1 order by col1 descThis gives the last ten records as per ur choice of "Order By" Column Link to comment Share on other sites More sharing options...
MrAdam Posted January 25, 2007 Share Posted January 25, 2007 <?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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now