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