Reputation: 347
I am using Jquery dynamic form plugin to generate dynamic fields in one of the forms I have in the application. the plugin works fine and it creates the field. I am still confused on what the best way is to get the form field values.
foreach ($this->input->post('product_item') as $key => $value) {
foreach($value as $element)
{
print_r($element);
}
}
returns
Array ( [color0] => red [size0] => s [quantity0] => 2 ) Array ( [color0] => green [size0] => m [quantity0] => 2 )
How do I get specific array value to store it in the Database.for e.g access Array ( [color0] => red [size0] => s [quantity0] => 2 )
and store it's value in Database.
Thanks for your time.
Upvotes: 0
Views: 1911
Reputation: 3951
By looking at this, you already know how to get the field values, just continue to recurse the array.
Would this not get you the desired result:
foreach ($this->input->post('product_item') as $key => $value) {
foreach($value as $element)
{
$color = $element['color0'];
$size = $element['size0'];
$quantity = $element['quantity0'];
mysql_query("INSERT INTO table (Color, Size, Quantity) VALUES ('$color', '$size', '$quantity')");
}
}
In your example, you have the array keys in both arrays end in 0
, these should increment, right?
Upvotes: 1