I want to show just the last three entries from a mysql database. I have the code to show the full table but could do with some help to tweak it to show just the last 3 entries from the table. Can anyone help me out? It's probably pretty easy for you php guys //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //select a database to work with $selected = mysql_select_db("#####",$dbhandle) or die("Could not select examples"); //execute the SQL query and return records $result = mysql_query("SELECT * FROM readersubmit ORDER BY id DESC"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo "<p>".$row['submit']. "</p>"; //display the results } //close the connection mysql_close($dbhandle); PHP:
Just Replace //execute the SQL query and return records $result = mysql_query("SELECT * FROM readersubmit ORDER BY id DESC"); with //execute the SQL query and return records $result = mysql_query("SELECT * FROM readersubmit ORDER BY id DESC LIMIT 0,3");