$conn = mysql_connect($entr,$user,$cred); //Set db connection
mysql_select_db("webshops",$conn);
$result = mysql_query('CALL storedproc');
$num_column = mysql_num_fields($result); //Get number of columns, for each column header get name and give them individual columns.
for($i=0;$i<$num_column;$i++) {
$csv_header .= '"' . mysql_field_name($result,$i) . '";';
}
$csv_header .= "\n";
$csv_row ='';
while($row = mysql_fetch_row($result)) {
for($i=0;$i<$num_column;$i++) {
$csv_row .= '"' . $row[$i] . '";';
}
$csv_row .= "\n";
}
ob_end_clean();
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename=OrderExport.csv');
echo $csv_header . $csv_row;
exit;
Once this CSV is downloaded and opened in Excel, the first row is always blank. The headers begin on the 2nd row. How can I prevent this from happening and have the headers begin on the first? Many Thanks.