Jump to content

Getting the latest updated row `ID` [index] ?!


shlomikalfa

Recommended Posts

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.