Ooops sorry, I meant to post this in the newbies section. How do I move it?
Hello,
I would like to update the existing rows of an array with data that has been submitted in a form.
The form is a table displaying the contents of an existing array ($newWords). One of the columns in the table has a checkbox and two others have an edit box to allow users to update the existing values. Once they submit the form, I try to loop round the array updating the existing array with values entered in the form.
I pass the existing array and word count via $SESSION. Here is the code I have to update the array:
for ($i = 0; $i <= $newWordCount - 1; $i++) {
$Sequence = $i + 1;
$newWords[$newWordCount++][newword] = $_POST[newword_.$Sequence];
$newWords[$newWordCount][wordtime] = $_POST[wordtime_.$Sequence];
$newWords[$newWordCount][notes] = $_POST[notes_.$Sequence];
}
The problem I have is that rather than updating the existing rows of the array it seems to be adding new rows.
Here is the contents of the updated array.
Array ( [0] => Array ( [word] => check [newword] => checked [sequence] => 1 [notes] => [wordtime] => ) [1] => Array ( [word] => this [newword] => [sequence] => 2 [notes] => Text to explain this [wordtime] => ) [2] => Array ( [word] => out [newword] => checked [sequence] => 3 [notes] => [wordtime] => ) [3] => Array ( [newword] => checked ) [4] => Array ( [wordtime] => 1 [notes] => check [newword] => checked ) [5] => Array ( [wordtime] => 2 [notes] => Text to explain this [newword] => checked ) [6] => Array ( [wordtime] => 3 [notes] => out ) )
I was expecting indexes 0-2 to be updated. Clearly I am doing something wrong but I'm not sure what. If someone can tell me how I update the existing rows I'd appreciate that.
Thanks,
Tim.