Computing.Net > Forums > Web Development > Last Updated

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Last Updated

Reply to Message Icon

Name: -Bryan-
Date: April 6, 2005 at 23:47:08 Pacific
OS: XP Pro
CPU/Ram: 3.4/1G
Comment:

Background:

Okay, here is an interesting problem that has been causing me to pull my hair out for the better part of 2 days. =)

I have a PHP page, of dynamically populated form fields basically, that displays things for different items.

For example, each row on this page displays make, model, color, etc. for a car. It pulls this information from a database and displays the information for all the cars at once.

The information is displayed as populated form fields so that the info can be changed for any or all of the cars.

I used to have a checkbox for each car, so that if you wanted to update the car in the database, you would check the checkbox. Then only the checked cars would be updated. This is obviously a pain in the a** if you need to update a bunch of them at once. You just want to change whatever information you need to change and update the whole thing.


Problem:

What I want to be able to do is determine what cars have been updated, and place a timestamp (i.e. last updated on xx/xx at xx:xx am or pm using the current time). I have the time/date stuff down just fine, but I can't seem to apply it to only the cars that have been updated. When I update one, it wants to change the Last Updated values for all the cars.

Any help would be GREATLY appreciated!

Thanks,

-=Bryan=-



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: April 7, 2005 at 06:47:42 Pacific
Reply:

I can think of three options - neither one particularly pretty.

You could do it with javascript - detect a change in any of the fields and change the value of a hidden field that acts like the old checkbox. It's javascript, so it won't always be enabled. Make sure you don't just set the hidden field on change (what if the user changes it, then decides to change it back?), set it on form submit where you can compare each textbox's default value against its value. This gets even uglier with other kinds of inputs - textareas, selects, checkboxes, etc. You may have to have more hidden inputs indicating the original values of those fields.

Option two is to do it in PHP - Before the update, grab all the old values, compare them against the POST data, and update only the ones that have changed. This one is not particularly pretty because of all the server-side overhead.

Option three is a combination of one and two - Send out hidden input fields for each writeable field that has the writeable field's original value, then in the PHP page compare original values to new values and update accordingly. This would be faster than two (no database query) and more reliable than three.

Both one and three would run into timing issues if more than one person is using the system at a time.

-SN


0

Response Number 2
Name: -Bryan-
Date: April 7, 2005 at 12:20:35 Pacific
Reply:

Hi SN, and thanks for the great help as always.

At least for the time being, I'm not overly concerned with the server overhead or multiple people using the site at once, as it's very small scale right now.

Option 3 (the combo) sounds very interesting. I might look into that.

I actually tried a version of Option 2, but couldn't get it to work. It just updated everything, and I'm not sure why.

All the updated form data is being put into an array and then updated that way. So what I did was read the original data from the database into an array as well, then compared the data in the two arrays to see what was updated. But it didn't work.

Bizarre, I'll look into a little more and let you know if it works out.

Thanks again!!!!

Bryan


0

Response Number 3
Name: Laler
Date: April 7, 2005 at 15:21:36 Pacific
Reply:

/snip
So what I did was read the original data from the database into an array as well, then compared the data in the two arrays to see what was updated
/snip

you sure you separate the cars correctly? like:

$car['ford1']['color'] = 'red';
$car['ford1']['make'] = 'Ford';
$car['honda1']['color'] = 'blue';
and so on..

do you use session? if so, make $_SESSION['car'] = $car;

then I think it'll be easier to compare with loops

on the form's target page:

populate a new array based on the submitted values something like:

$carNew['ford1']['color'] = $_POST['fordcolor'];

so that the new array is similar with the 1st array, only the array name is different.
and so on...

now you loop, something like:

// create a container for changed cars
$changed = array();

foreach ($_SESSION['car'] as $key => $value){

// this is the comparation
if ($_SESSION['car'][$key] != $carNew[$key]){

// record the car name
$changed[] = $key;

}

}

now $changed is an array of changed carnames...

did that help?

---
Site of the Day


0

Response Number 4
Name: -Bryan-
Date: April 8, 2005 at 00:50:51 Pacific
Reply:

SN, thank you again for the help. I stuck with Option 2 and it works great now!

Laler, thank you much for the help too. Your info did help. I'm not sure what the heck I was doing the past couple days, but the array for the existing info in the database I guess is the thing that wasn't working properly. I re-coded it today and it's working great now.

Again, thank you for the help gentlemen. It's indeed appreciated!

Bryan


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Gif alpha transparency Javascript to save last p...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Last Updated

Weather information on site www.computing.net/answers/webdevel/weather-information-on-site/1921.html

css help www.computing.net/answers/webdevel/css-help/2065.html

php mysql www.computing.net/answers/webdevel/php-mysql/759.html