detect if a record is open by other user?

Discussion in 'PHP' started by srdva59, Aug 2, 2010.

  1. #1
    hi,
    i need know if there is any way to lock a record for exclusive editing
    in mysql for other user can´t edit the same record at same time.
    The ideia is before the user edit the record he see that the current record
    is open for other user.
    it´s possible to do something like this?
    thanks a lot for your help
    :)
     
    srdva59, Aug 2, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    If its for admins how about putting a time between edits, say 5mins.

    So in theory when you open the item, it would say

    Last Access: some date/time By: Admin2

    ..and if 5 minutes have pasted the edit panel will show or it could say

    'You must wait '-time' before you can edit this item"

    Would something like that do ?
     
    MyVodaFone, Aug 2, 2010 IP
  3. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #3
    You could do it the other way and not lock it, but check that the content has not been edited since the current user has loaded it, and on them requesting an update.

    So, user1 loads the data. User2 then loads the data. User1 submits an edit. User2 submits an edit but is notified that there has been changes, options to overwrite, merge, diff etc. You'd probably need to store the last edited date in the db somewhere, then on the edit form so it can be checked on submit.
     
    mfscripts, Aug 4, 2010 IP
  4. freshdevelopment

    freshdevelopment Notable Member

    Messages:
    1,303
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    240
    #4
    I would say this is the best solution, but as an alternative you could have a field to "lock" the record (0 or 1, or even a user_id) which is set when someone opens the page to edit. Anyone else trying to access it while it is locked will get a message to wait. Make sure you encourage the users to "cancel" or "save" when they have done, instead of closing a browser window, as it could leave a lock on. You would have to have a timeout of some kind (maybe 20 minutes depending on what is editing) so you might need a second field called something like "locktime"
     
    freshdevelopment, Aug 4, 2010 IP