Экспорт данных csv php mysql – все данные экспортируются в один столбец

Мне нужно имя, данное местоположение мобильных заметок phonenumber для всех будет в отдельных столбцах моего экспорта csv, используя скрипт php ниже. Текущий код экспортирует все выбранные данные в один столбец для каждой записи. Спасибо!

$result = mysql_query('SELECT who as "Name,Given" , phonenumber as "mobile", notes, location FROM `phpbb_phonelist` WHERE `activenumber` = 1'); if (!$result) die('Couldn\'t fetch records'); $num_fields = mysql_num_fields($result); $headers = array(); for ($i = 0; $i < $num_fields; $i++) { $headers[] = mysql_field_name($result , $i); } $fp = fopen('php://output', 'w'); if ($fp && $result) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="phonelist.csv"'); header('Pragma: no-cache'); header('Expires: 0'); fputcsv($fp, $headers); while ($row = mysql_fetch_row($result)) { fputcsv($fp, array_values($row)); } die; 

Solutions Collecting From Web of "Экспорт данных csv php mysql – все данные экспортируются в один столбец"

Используйте этот код

 // output headers so that the file is downloaded rather than displayed header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=data.csv'); // create a file pointer connected to the output stream $output = fopen('php://output', 'w'); // output the column headings fputcsv($output, array('Column 1', 'Column 2', 'Column 3')); // fetch the data mysql_connect('localhost', 'username', 'password'); mysql_select_db('database'); $rows = mysql_query('SELECT field1,field2,field3 FROM table'); // loop over the rows, outputting them while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);