function __import__csv
Posted: Thu Nov 27, 2008 7:33 am
Hi Steve, hi all,
i have a little problem when importing csv-data to my database. I was using the import-filter called function __import__csv like follows:
It works fine apart from two mistakes you can see in the following picture.
1. The headline labels are imported which they don't.
2. There is imported one empty row too much.
How can I avoid this? I found http://xataface.com/forum/viewtopic.php?t=4156#20888 in the forum but was wondering if there could be done something in the function itself in my tables delegate class without changing the export_csv.php file. Here is my temporary table before importing the records:
Thanks a lot for any hints solving these probs
Markus
i have a little problem when importing csv-data to my database. I was using the import-filter called function __import__csv like follows:
- Code: Select all
function __import__csv(&$data, $defaultValues=array()){
// build an array of Dataface_Record objects that are to be inserted based
// on the CSV file data.
$records = array();
// first split the CSV file into an array of rows.
$rows = explode("\n", $data);
foreach ( $rows as $row ){
// We iterate through the rows and parse the values to that they can be stored in a Dataface_Record object */
list($v_b3_ID, $B3_ID_result, $time, $b_m3_FM, $m_m3_FM, $b_m3_oTM, $m_m3_oTM, $timestamp) = explode(';', $row);
$record = new Dataface_Record('versuch', array());
// We insert the default values for the record.
$record->setValues($defaultValues);
// Now we add the values from the CSV file.
$record->setValues(
array(
'v_b3_ID'=>$v_b3_ID,
'B3_ID_result'=>$B3_ID_result,
'time'=>$time,
'b_m3_FM'=>$b_m3_FM,
'm_m3_FM'=>$m_m3_FM,
'b_m3_oTM'=>$b_m3_oTM,
'm_m3_oTM'=>$m_m3_oTM,
'timestamp'=>$timestamp
)
);
// Now add the record to the output array.
$records[] = $record;
}
// Now we return the array of records to be imported.
return $records;
}
It works fine apart from two mistakes you can see in the following picture.
1. The headline labels are imported which they don't.
2. There is imported one empty row too much.
How can I avoid this? I found http://xataface.com/forum/viewtopic.php?t=4156#20888 in the forum but was wondering if there could be done something in the function itself in my tables delegate class without changing the export_csv.php file. Here is my temporary table before importing the records:
Thanks a lot for any hints solving these probs
Markus