Created
July 18, 2010 20:33
-
-
Save lukegb/480688 to your computer and use it in GitHub Desktop.
This file contains 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
$q=mysql_query("SELECT * from sales") or die(mysql_error()); | |
$rows = array(); | |
while($row = mysql_fetch_assoc($q)){ | |
$newrow = array(); | |
foreach($row as $x) | |
{ | |
if (is_numeric($x)) | |
{ | |
$newrow[] = '="'.$x.'"'; | |
} | |
else { | |
$newrow[] = $x; | |
} | |
} | |
$rows[] = $newrow; | |
unset($newrow); | |
} | |
$fp = fopen('file.csv', 'w'); | |
foreach ($rows as $line) { | |
fputcsv($fp, $line); | |
} | |
fclose($fp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment