Saturday, 10 January 2015

PHP & MySQL find the last entry in the database




1
2
So you are looking for the last entry in a table for your database that has auto increment.  Well I have this to share with you. Use the mysql_insert_id() function.


mysql_query("INSERT INTO table1 (product) values ('$somethin')");
$lastID = mysql_insert_id();


1
echo $lastID;

$query = "SELECT * FROM table1 WHERE id=$lastID"; //select from DB image url and set order
 $result = mysql_query ($query);
 
 while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
 echo ($row['something']. "</br>");
 }

No comments:

Post a Comment