Need help - Updating multiple rows with one form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
arpowers
Forum Commoner
Posts: 76
Joined: Sun Oct 14, 2007 10:05 pm
Location: san diego, ca

Need help - Updating multiple rows with one form

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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!
User avatar
arpowers
Forum Commoner
Posts: 76
Joined: Sun Oct 14, 2007 10:05 pm
Location: san diego, ca

Post 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!
Post Reply