I am looking for a php function which returns the most recent entry into a mysql table.
4 Answers
You can use mysql_insert_id() - http://php.net/manual/en/function.mysql-insert-id.php, which returns the most recent key from the database. You could then do a query to select it. For example
$id = mysql_insert_id(); $result = mysql_query("SELECT * FROM table WHERE id = ".$id);
Hope that helps!
Comments
Get the last row, assuming id is the primary key (with auto increment):
mysql_fetch_array(mysql_query("SELECT * FROM table ORDER BY id DESC LIMIT 1));
1 Comment
You can use
mysql_inset_id to retrieve recently added rows id.
But that should be used to immediately after the insert query.
mysql_insert_id() acts on the last performed query, be sure to call mysql_insert_id() immediately after the query that generates the value.
If you want to retrieve it later you can use a select query
select * from table order by id desc limit 1;
1 Comment
int mysql_insert_id ([ resource $link_identifier ] )
http://php.net/manual/en/function.mysql-insert-id.php
Maybe thats what you looking for