Created
January 15, 2009 23:06
-
-
Save mikedamage/47688 to your computer and use it in GitHub Desktop.
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
$result = mysql_query("SELECT * FROM table ORDER BY column DESC"); | |
// I hard-code the column names so I can capitalize, add spaces, etc. | |
$fields = '"User ID","Name","Email","Registration Date"'."\n"; | |
// Iterate through the rows of data | |
while ($row = mysql_fetch_assoc($result)) | |
{ | |
$fields .= '"'.$row['id'].'","'.$row['name'].'","'.$row['email'].'","'.$row['registration_date'].'"'."\n"; | |
} | |
// Set our headers | |
header('Content-type: text/csv'); | |
// To display data in-browser, change the header below to: | |
// header("Content-Disposition: inline"); | |
header("Content-Disposition: attachment; filename=event_registrations.csv"); | |
// Output our data | |
echo $fields; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment