How do I fetch the last record in a MySQL database table using PHP? -
I want to get the last result in the MySQL database table using PHP. How would I go about doing this?
I have 2 columns in the table, Message ID (Auto) & amp; message.
I already know how to connect to the database.
Usage:
& lt ;? Php $ result = mysql_query ('select t.messageid, t.messageid by DESC LIMIT 1, t.message from TABLE T ORDER) or die (' invalid query: '. Mysql_error ()); // Prints print to print ($ line = mysql_fetch_assoc ($ result)) {echo $ line ['messageid']; Echo ['message'] per line; } // Set the results related to the results for free // This script is done automatically at the end of mysql_free_result ($ result); ? & Gt;
SQL query:
select t.messageid, t.message by T. T. CDIDIDCCE Border 1 by the table T command
... uses order bye to set the value so that the highest result is the first line in the resultset. LIMIT says that in all those rows, only for the first time is actually actually returned in the resultset because messageid
is automatically increment, the highest value is the most recent one ...
Comments
Post a Comment