Export to CSV file and download – PHP


function CSVExport() {
$query=”SELECT id,email FROM `newsletterusers` WHERE `status` = 1”;
$sql_csv = mysql_query($query) or die(“Error: ” . mysql_error()); //Replace this line with what is appropriate for your DB abstraction layer

header(“Content-type:text/octect-stream”);
header(“Content-Disposition:attachment;filename=newsletterusers.csv”);
while($row = mysql_fetch_row($sql_csv)) {
print ‘”’ . stripslashes(implode(‘”,”’,$row)) . “"n”;
}
exit;
}

Advertisements