Re: [PHP] CSV Files
- From: eric.butera@xxxxxxxxx ("Eric Butera")
- Date: Wed, 22 Oct 2008 20:05:42 -0400
On Wed, Oct 22, 2008 at 7:59 PM, Jason Todd Slack-Moehrle
<mailinglists@xxxxxxxxxxxxxxx> wrote:
Hi All,
I need to take a record in MySQL and have my user get it as a CSV File. I am
OK with most everything, except when I create the CSV file, I write out the
column headers then I need to write out the data.
After I right out the column headers do I have to put a '/n' to have it
start a new line in the CSV file? I think I do.
Here is what I have (a snippet):
header("Content-type: application/csv");
header($filenameString);
header("Pragma: no-cache");
header("Expires: 0");
echo $map_BORROWER_FIRST_NAME.", ";
echo $map_BORROWER_LAST_NAME.", ";
echo $map_BORROWER_SSN.", ";
echo $map_BORROWER_HOME_PHONE.", ";
echo $map_BORROWER_DOB;
echo "/n";
echo $row[BORROWER_FIRST_NAME].",";
echo $row[BORROWER_LAST_NAME].",";
echo $row[BORROWER_SSN].",";
echo
$row[BORROWER_HOME_PHONE_FIRST].$row[BORROWER_HOME_PHONE_MIDDLE].$row[BORROWER_HOME_PHONE_LAST].",";
echo
$row[BORROWER_DOB_MONTH].$row[BORROWER_DOB_DAY].$row[BORROWER_DOB_YEAR];
When I run this, I see my column names, but not the data. The query seems to
execute just fine....
Any advice?
Thanks,
-Jason
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
When I work with things like this I always use fputcsv. One neat
little trick is to use streams.
$o = fopen("php://output", "w");
// select first row and use array keys for header row then rewind
// while results do this
fputcsv($o, $row)
.
- References:
- CSV Files
- From: Jason Todd Slack-Moehrle
- CSV Files
- Prev by Date: CSV Files
- Next by Date: Re: [PHP] CSV Files
- Previous by thread: CSV Files
- Next by thread: Re: [PHP] CSV Files
- Index(es):
Relevant Pages
|
Loading