0

I have a form with several select and text boxes that gets dynamically generated from a database query. The number of rows (The form lives in a html table) depends on how many records gets returned from the database. For instance:

Row 1 - MUStatus(dropdown), IPlan(dropdown), ATT(text box) Row 2 - MUStatus(dropdown), IPlan(dropdown), ATT(text box) Row 3 - MUStatus(dropdown), IPlan(dropdown), ATT(text box) ... ... ... Row 10 - MUStatus(dropdown), IPlan(dropdown), ATT(text box)

Not all rows are going to be updated all the time. Maybe a user gets a 10-row form and updates only one. My processing script needs to loop through all rows to figure out which one has changed in order to update. This causes the update query to run 10 times even if the user only updates one row. How can I get it to update only the number of rows that has been changed on the form?

Currently this is my processing script (not sanatized yet. Just in test mode)

for($i = 0; $i < $_POST['totalRecords']; $i++){
    if($_POST['muStatus'] != $providerMUStatusArray[$i] ||         
       $_POST['att1IncentivePlanDropDown'!= $providerATT1IncentivePlanArray[$i] ||
       $_POST['att1AttestationNumber'!=  $providerATT1NumberArray[$i]){
        UPDATE QUERY GOES HERE
    }//END IF
}//END FOR

Any help is appreciated

2 Answers 2

1

This is how I would do it: I would add a hidden field in each row called "Updated" with a start value of 0 then use JQuery or just JavaScript to set it to 1 every time a value in that row is changed.

Even better, I would use AJAX to update each row as soon as the user is done editing it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Sunknight0. I swear I tried the jQuery path, but got stuck and had to go back to the conventional way due to a tight deadline.
0

I would create a session and store the values you expect. Then when the form is submitted you just check to see if the submitted value equals the session saved value. If it does not equal it then process.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.