cujo Posted April 29, 2006 Share Posted April 29, 2006 Hi, I'm new to these forums and I'd appreciate it if you could help with a problem I'm having.I have a table where there is an auto_increment value that serves as the ID for each entry into the table. In my script I insert a new entry into the table, and I need the value of the ID for the entry that was just inserted. Right now this is what I'm doing:$id_query = mysql_query("SELECT id FROM table ORDER BY id DESC LIMIT 1");$id = mysql_result($id_query,0);That should get the ID for most recent entry from the table, right? There's one problem. Multiple entries are inserted into the table during the execution of the script, and I'm worrying that if more than one person is using the script at the same time that the values might get mixed up. Can anyone shed some light onto this problem? Link to comment https://forums.phpfreaks.com/topic/8723-getting-the-id-of-the-most-recent-database-entry/ Share on other sites More sharing options...
AndyB Posted April 29, 2006 Share Posted April 29, 2006 [a href=\"http://ca.php.net/manual/en/function.mysql-insert-id.php\" target=\"_blank\"]php.net/manual/mysql-insert-id[/a] - does that help? Link to comment https://forums.phpfreaks.com/topic/8723-getting-the-id-of-the-most-recent-database-entry/#findComment-32015 Share on other sites More sharing options...
cujo Posted April 29, 2006 Author Share Posted April 29, 2006 [!--quoteo(post=369941:date=Apr 29 2006, 03:23 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Apr 29 2006, 03:23 PM) [snapback]369941[/snapback][/div][div class=\'quotemain\'][!--quotec--][a href=\"http://ca.php.net/manual/en/function.mysql-insert-id.php\" target=\"_blank\"]php.net/manual/mysql-insert-id[/a] - does that help?[/quote]Awesome, thanks a lot man. Link to comment https://forums.phpfreaks.com/topic/8723-getting-the-id-of-the-most-recent-database-entry/#findComment-32018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.