Created
January 23, 2013 15:51
-
-
Save dantoncancella/4608488 to your computer and use it in GitHub Desktop.
onverting the data base return to csv form(for excel)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* $result should be the return of a function of line "fetch_assoc", returned of a query on the data base | |
*/ | |
if(!empty($result)) { | |
$filename = date('Ymd').'.csv'; | |
$header = array_values(array_keys($result[0])); | |
$out = '"'.implode('";"', $header)."\"\r\n"; | |
header("Content-type: text/csv; charset=utf-8"); | |
header("Content-Disposition: attachment; filename=".$filename); | |
foreach ($result as $key => $value) { | |
$out .= '"'.implode('";"', $value)."\"\r\n"; | |
} | |
echo $out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment