I'm trying to insert multiple rows into a field collection from a CSV that's been uploaded. I can successfully do one row, but it fails with the foreach. I am grateful for any help. Thank you.
function apa_import_form_submit($form, &$form_state) {
< ... snip .. >
$parsed = apa_parse_csv($f);
drupal_set_message("<pre>".print_r($parsed, TRUE)."</pre>");
foreach ($parsed as $data) {
db_insert('field_data_field_last')
->fields(array(
'entity_type' => 'field_collection_item',
'bundle' => 'field_list',
'deleted' => 0,
'entity_id' => $fid,
'revision_id' => $fid,
'language' => 'und',
'delta' => 0,
// If I comment out the foreach and replace $date[1] below with $parsed[0][1], the first row from the csv is imported successfully
'field_last_value' => $data][1],
'field_last_format' => NULL,
))
->execute();
}
}
output from the drupal_set_message:
Array
(
[0] => Array
(
[0] => Last Name
[1] => First Name
[2] => Phone
[3] => Ref #
)
[1] => Array
(
[0] => Simpson
[1] => Marge
[2] => 2
[3] => ref1
)