PHP function which returns the most recent row entered into a mysql function
I am looking for a php function wh开发者_StackOverflowich returns the most recent entry into a mysql table.
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!
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));
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;
int mysql_insert_id ([ resource $link_identifier ] )
http://php.net/manual/en/function.mysql-insert-id.php
Maybe thats what you looking for
精彩评论