Skip to content

Instantly share code, notes, and snippets.

@lukegb
Created July 18, 2010 20:33
Show Gist options
  • Save lukegb/480688 to your computer and use it in GitHub Desktop.
Save lukegb/480688 to your computer and use it in GitHub Desktop.
$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