1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
$csv_filename = 'liste-participant_'.date('d-m-Y').'.csv';
$sql = 'SELECT * FROM ma_table ORDER BY id';
$query = $connect_db->query($sql);
$query->setFetchMode(PDO::FETCH_ASSOC);
$count = 30;
$users = array();
if ($count > 0) {
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$users[] = $row;
}
}
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename='.$csv_filename);
$output = fopen('php://output', 'w');
fputcsv($output, array('col1', 'col2', 'col3', 'col4', 'col5', 'col6');
if (count($users) > 0) {
foreach ($users as $data) {
fputcsv($output, $data);
}
}
fclose($output); |