Reputation: 1211
I have below script to export MySQL data to csv file.This script export everything inside the while loop but I want to put constant value in a 2nd column or just want to keep 2nd column empty and put MySQL data in column 1 and column 3.
// output the column headings
fputcsv($output, array('Column 1', 'Column 2', 'Column 3'));
// fetch the data
$rows = mysql_query('SELECT field1,field2 FROM table');
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);
Upvotes: 0
Views: 130
Reputation: 41
You already have field1 (i.e-Column1) and field2(i.e-Column3)
so just add Null at 2nd position like below
$insert = array( '' );
array_splice( $row, 1, 0, $insert );
then use
fputcsv($output, $row);
Upvotes: 1