Re: CSV Files

From: Date: Thu, 23 Oct 2008 00:05:42 +0000
Subject: Re: CSV Files
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-282317@lists.php.net to get a copy of this message
On Wed, Oct 22, 2008 at 7:59 PM, Jason Todd Slack-Moehrle <mailinglists@mailnewsrss.com> 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)

« previous php.general (#282317) next »