shadiadiph Posted March 23, 2009 Share Posted March 23, 2009 how do i get the value of the last id inserted into the database again sorry i have forgotten Link to comment https://forums.phpfreaks.com/topic/150790-mm-how-do-i-get-the-value-of-the-last-id/ Share on other sites More sharing options...
lonewolf217 Posted March 23, 2009 Share Posted March 23, 2009 i pulled this out which has worked for me //get the ID of the most recent addition to the table $sql = mysql_query("SELECT SCOPE_IDENTITY() AS [sCOPE_IDENTITY]"); $row = mysql_fetch_array($sql); $newID = $row['SCOPE_IDENTITY']; Link to comment https://forums.phpfreaks.com/topic/150790-mm-how-do-i-get-the-value-of-the-last-id/#findComment-792208 Share on other sites More sharing options...
Psycho Posted March 23, 2009 Share Posted March 23, 2009 Well, personally, i would just use the command that is already built into the application: mysql_insert_id() http://us.php.net/mysql_insert_id mysql_insert_id mysql_insert_id — Get the ID generated from the previous INSERT operation OR, if you need to use it in a query: $query = "UPDATE table SET foo = 'bar' WHERE id = LAST_INSERT_ID()"; Link to comment https://forums.phpfreaks.com/topic/150790-mm-how-do-i-get-the-value-of-the-last-id/#findComment-792214 Share on other sites More sharing options...
shadiadiph Posted March 24, 2009 Author Share Posted March 24, 2009 mm ok thanks i shall try it later need to get some sleep first Link to comment https://forums.phpfreaks.com/topic/150790-mm-how-do-i-get-the-value-of-the-last-id/#findComment-792220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.