/* Header file to includes.
fopen is use to open a file in write mode here.
fputcsv function is use to output the CSV file having the name of columns and data coming from database. */
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=attendance.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('Column name 1','column name 2'));
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
fputcsv($output, $row);
0 Comment(s)