Update only changed fields
Posted: Fri Nov 05, 2004 9:28 pm
Alright, I'm trying to find the best way to update a db record but only the field(s) that has(have) changed.
each record has nine different elements which the user enters on one page, which is how everything gets into the database in the first place. If the user calls up the records later from a certain page, some of the form fields are populated by returned record elements. The user then has the choice to update the form field and change the record or records.
I am trying to find the easiest way to have it figure out if the form field(s) is(are) different from the current values in the record(s). I have thought that I could have it compare every single form field and if they're different have it update but thought there might be an easier way.
How about if I save the $row[] array elements somehow (in a $_SESSION, I guess) and compare old results with the new $_POST? Thing about that that makes me pause is that it will probably be a two dimensional array and I don't know how bad it would be to fill up $_SESSION with data I don't even know if I'll be using.
Also, each form element (and therefore each record element) has it's own submit button because I was thinking that I could identify which submit button was pushed but wouldn't I then either need to use javascript or give each form element its own form?
Does any of that sound doable? Maybe someone has a cleaner idea?
Thanks
each record has nine different elements which the user enters on one page, which is how everything gets into the database in the first place. If the user calls up the records later from a certain page, some of the form fields are populated by returned record elements. The user then has the choice to update the form field and change the record or records.
I am trying to find the easiest way to have it figure out if the form field(s) is(are) different from the current values in the record(s). I have thought that I could have it compare every single form field and if they're different have it update but thought there might be an easier way.
How about if I save the $row[] array elements somehow (in a $_SESSION, I guess) and compare old results with the new $_POST? Thing about that that makes me pause is that it will probably be a two dimensional array and I don't know how bad it would be to fill up $_SESSION with data I don't even know if I'll be using.
Also, each form element (and therefore each record element) has it's own submit button because I was thinking that I could identify which submit button was pushed but wouldn't I then either need to use javascript or give each form element its own form?
Does any of that sound doable? Maybe someone has a cleaner idea?
Thanks