Re: [PHP] CSV Files



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)
.



Relevant Pages

  • CSV Files
    ... 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. ... Any advice? ...
    (php.general)
  • Parsing CSV vertically and horizontally
    ... The data file is normal CSV file. ... first we read config file for data colum names: ... echo Read %COUNT% columns. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Convert CSV file to multiple worksheets
    ... are supposed to be appending the USBdevices string to the end of the first line only, ... And then, because the column headers don't show up, the count variable I have as the last value in the array defining the number ... So I'm wondering if I need to add a loop that counts the number of lines in the CSV file. ... Each WriteLine will write a new line to the CSV file because it inserts a newline character, so you can't use it to append data. ...
    (microsoft.public.scripting.vbscript)
  • Numbers are interpreted as varchar columns by the text file connection
    ... I am using a Text File connection and the input is a CSV file ... and the first row of the file as column headers. ... a .xls file and use a .XLS file as the connection with column headers ...
    (microsoft.public.sqlserver.dts)
  • Re: Bash + SSH problem.
    ... The script has grown a lot and now has ... echo "1. ... i need to put the output of ifconfig in a csv file but i ... interface name first, the result will be like i.e. ...
    (comp.unix.shell)

Loading