EDIT: Copied wrong part of function into this question, below is the appropriate one.
$values = mysql_query("SELECT lname, fname, email, dtelephone, etelephone, contactwhen, thursday,
friday, saturday, sunday, monday, comments FROM volunteers_2009 WHERE venue_id = $venue_id");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j].", ";
}
$csv_output .= "\n";
}
I have comments that may have a comma in it, and even double quotes, when it has a comma in the comment field, it throws off the entire csv file.
The code below is how it loads the data into the csv string, to put into a csv file.
How do I get it to export the comments field data properly?
You should check out fputcsv()
. There are some useful comments there as well.
int fputcsv ( resource $handle , array $fields [, string $delimiter = ',' [, string $enclosure = '"' ]] )
fputcsv() formats a line (passed as a fields array) as CSV and write it (terminated by a newline) to the specified file handle.
Enclose the field in double quotes. Double up any embedded double quotes.
ordinary field,"field with , in it","field with double double quote ("""")"
Note that this is very, very close to the question Dealing with commas in a CSV file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With