Page 1 of 1

Need help - Updating multiple rows with one form

Posted: Sun Oct 14, 2007 10:15 pm
by arpowers
Hey Everyone,
I'm new here but I like the site.
I have a coding question.

I am attempting to update multiple database rows with one form submit. Here is a the post data:

Code: Select all

[12_title] => title
    [12_journal] => journal
    [12_Month] => Month
    [12_Day] => Day
    [12_Year] => Year
    [7_title] => title
    [7_journal] => journal
    [7_Month] => Month
    [7_Day] => Day
    [7_Year] => Year
    [2_title] => title
    [2_journal] => journal
    [2_Month] => Month
    [2_Day] => Day
    [2_Year] => Year
    [17_title] => title
    [17_journal] => journal
    [17_Month] => Month
    [17_Day] => Day
    [17_Year] => Year
As you can see the numeric index in the front is meant to be the row id.

I would like to put this data into the form:

Code: Select all

array[id][field] = value
like...
array[17][journal] = title

what are the steps you guys recommend???
Thanks in advance for any help or suggestions:)
Andrew

Posted: Sun Oct 14, 2007 10:25 pm
by Kieran Huggins
if you control the input forms, change the field names to:

Code: Select all

<input name="something[12][title]" />
then no conversion is necessary!

Posted: Sun Oct 14, 2007 11:00 pm
by arpowers
Thanks for the quick reply.. great suggestion...
is this considered 'good practice' technique?

Also in the interim I found that...

Code: Select all

foreach($full_array as $key => $value){
	$ex_array = explode("_", $key);
	$id = $ex_array[0];
	$new_key = end($ex_array);
	$this_array[$id][$new_key] = $value;
}
works as well.. but your solution may be better:)

are there other methods??
Thanks!