UPDATE (code as asked for):
$result = mysql_query('SELECT * FROM `some_table`');
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="export.csv"');
header('Pragma: no-cache');
header('Expires: 0');
fputcsv($fp, $headers);
while ($row = mysql_fetch_row($result))
{
fputcsv($fp, array_values($row));
}
die;
}
$result = mysql_query('SELECT who, phonenumber, notes, location FROM `phpbb_phonelist` WHERE `activenumber` = 1');
if (!$result) die('Couldn\'t fetch records');
I'm trying to change the header for who, phonenumber, notes, and location. I've tried using an as statement (see below), but it creates line breaks in the header:
$result = mysql_query('SELECT who as "Test1", phonenumber as "Test 2", notes as "Test 3", location as "Test 4" FROM `phpbb_phonelist` WHERE `activenumber` = 1');
if (!$result) die('Couldn\'t fetch records');
Output of the above:
who,"Phone Number",notes,location