shlomikalfa Posted May 25, 2008 Share Posted May 25, 2008 hey guys, I'm trying to make a PHP script that will provide certain information only to the first requester, thus i'm trying to first UPDATE it with a ""TAKEN"" status, and then SELECT it's column and send to the requester... In that manner there can't be 2 people getting the same entry because it'll already be taken before the select... The main issue i'm having now is how do i get the latest UPDATED entry ID ?! seems like: mysql_affected_rows($link) doesn't give the correct index... Quote Link to comment https://forums.phpfreaks.com/topic/107193-getting-the-latest-updated-row-id-index/ Share on other sites More sharing options...
BlueSkyIS Posted May 25, 2008 Share Posted May 25, 2008 mysql_affected_rows() returns the number of affected rows. you'll need to select the row you're going to update, get it's ID, then update it based on the id. then you're already got the id. if you're concerned about the rare case where 2 more more individuals might get the same record at the same time, you might want to look into record locking. Quote Link to comment https://forums.phpfreaks.com/topic/107193-getting-the-latest-updated-row-id-index/#findComment-549568 Share on other sites More sharing options...
shlomikalfa Posted May 25, 2008 Author Share Posted May 25, 2008 Well.. i've thought about the way you're saying but my current case is even better... that is if there is no way to get the latest updated ID... ATM i am using this methode. UPDATE `table` SET `column` = "Taken", `column2` = $UserName WHERE `column` = "Opened", `column2` = "" that way only 1 can be the first to update that entry with his name... then i am picking up the entry with his name.... SELECT * FROM `table` WHERE `column` = "Taken", `column2` = $UserName ORDER BY `DATE` DESC but i was hoping there is a more direct way to get the ID of what we've just updated.... how does the PHPMyAdmin knows what to show after an update ?! Quote Link to comment https://forums.phpfreaks.com/topic/107193-getting-the-latest-updated-row-id-index/#findComment-549574 Share on other sites More sharing options...
mga_ka_php Posted May 28, 2008 Share Posted May 28, 2008 is your id dynamic? mysql_insert_id(); Quote Link to comment https://forums.phpfreaks.com/topic/107193-getting-the-latest-updated-row-id-index/#findComment-551339 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.