Jump to content

Recommended Posts

Just looking for ideas on this. Trying to stick with php/MySQL only for a solution. (Running XAMPP - PHP 5.0.5 and mySQL 2.6.4)

I need to come up with a way to lock a record when a user has it opened in "Edit" mode. I have lists of records which, when displayed, offer the user a "View" or "Edit" link for that record.

I was thinking I should have a field for each record called "locked" and if a user selects "Edit" then that record gets flagged with "Y" (meaning locked). If someone else where to then try and "Edit" the same record it would kick back a message telling them it was currently being edited (I can do this, no worries there.)

But, if the original user that locked it, were to navigate away (intentional or accidental) and not submit their changes then how would I get the record to flag back to "N" (meaning unlocked)?

I need to try and also have this work if they were to close their browser accidently and say needed to get right back into the same record to "Edit" still.
Link to comment
https://forums.phpfreaks.com/topic/7727-record-locking/
Share on other sites

use an "is_locked" field.

When the edit page is opened, have an update query run and set is_locked to time()
When the edit is completed, have the update query run and set is_locked to nothing ... ie ""

If the timespan for the file to be edited has elapsed, which for example could be 5 minutes... just allow it to be edited.

Something like;

[code]
<?php
$time_now = time();
$allowed_time = $time_now-300;
if($is_locked<$allowed_time) { echo "Editing is allowed"}
[/code]

Obviously this would need fleshing out, but you get the idea.
Link to comment
https://forums.phpfreaks.com/topic/7727-record-locking/#findComment-28199
Share on other sites

[!--quoteo(post=366040:date=Apr 18 2006, 11:22 AM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Apr 18 2006, 11:22 AM) [snapback]366040[/snapback][/div][div class=\'quotemain\'][!--quotec--]
use an "is_locked" field.

When the edit page is opened, have an update query run and set is_locked to time()
When the edit is completed, have the update query run and set is_locked to nothing ... ie ""

If the timespan for the file to be edited has elapsed, which for example could be 5 minutes... just allow it to be edited.

Something like;

[code]
<?php
$time_now = time();
$allowed_time = $time_now-300;
if($is_locked<$allowed_time) { echo "Editing is allowed"}
[/code]

Obviously this would need fleshing out, but you get the idea.
[/quote]


Very cool, will give that a go. That would appear to work no matter the misnavigation or accidental browser closing. The user would just have to wait the specified time to update that record if they goofed.

Thanks for the quick response!
Link to comment
https://forums.phpfreaks.com/topic/7727-record-locking/#findComment-28201
Share on other sites

You could even set the "This can't be edited" message to incorporate the time when they will be able to edit it... ie

"You cannot edit this record until 16:38"

If you wanted to be really cocky you could let them be notified when the record became available for editing, and if multiple people are waiting to edit the record, have them held in a queue lol
Link to comment
https://forums.phpfreaks.com/topic/7727-record-locking/#findComment-28206
Share on other sites

[!--quoteo(post=366047:date=Apr 18 2006, 11:35 AM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Apr 18 2006, 11:35 AM) [snapback]366047[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You could even set the "This can't be edited" message to incorporate the time when they will be able to edit it... ie

"You cannot edit this record until 16:38"

If you wanted to be really cocky you could let them be notified when the record became available for editing, and if multiple people are waiting to edit the record, have them held in a queue lol
[/quote]


LOL! Well I think the "you cannot edit until..." message is a really good idea to use. I don't think we are going to run into a problem where they need to be notified, but a great suggestion.

And yeah...I might just do that just be "really cocky" about it...haha!
Link to comment
https://forums.phpfreaks.com/topic/7727-record-locking/#findComment-28215
Share on other sites

During the development on the system i am working on for client management here, there have been loads of instances of me thinking "we don't really need this, but for my own amusement i will add it anyway" and then a few days later, while working on something completely unrelated the code has been really useful.

It's quite good to make things as indepth as possible sometimes, because you never know how things will pan out. In 6 months time it'd be easier to be able to just "turn on" some code that's already in place, than to have to try and bolt on something to do the job later.

This has actually given me an idea for something i am working on... thanks for that lol.
Link to comment
https://forums.phpfreaks.com/topic/7727-record-locking/#findComment-28220
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.