How to update csv column names with database table header

Posted by user1523311 on Stack Overflow See other posts from Stack Overflow or by user1523311
Published on 2012-12-14T07:30:29Z Indexed on 2012/12/14 17:04 UTC
Read the original article Hit count: 143

Filed under:
|
|

I am facing this problem some past days and now frustrate because I have to do it.

I need to update my CSV file columns name with database table header. My database table fields are different from CSV file. Now the problem is that first I want to update column name of CSV file with database table headers and then import its data with field mapping into database.

Please help me I don't know how I can solve this.

This is my php code:

$file      = $_POST['fileName'];
$filename  = "../files/" . $file;
$list      = $_POST['str'];
$array_imp = implode(',', $list);
$array_exp = explode(',', $array_imp);
$fp        = fopen("../files/" . $file, "w");
$num       = count($fp);

for ($c = 0; $c < $num; $c++) {
    if ($fp[c] !== '') {
        fputcsv($fp, $array_exp);
    }
}

fclose($fp);

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql