In csv file i need a comma in column value.
Here is the mysql query:
$q_pack = "select p.filename, p.version, dt.name as external,p.internal
from cert c
join packages p on c.package_id=p.id
left join documents dt on p.id=dt.package_id
left join documents doc on doc.id=d.document_id
where c.certificate_id=100";
$res_pack = db_query($q_pack);
if ($res_pack){
$fp = fopen('sample.csv', 'w');
$title = "filename, version, external,internal";
fwrite($fp, $title);
while ($pack_row = db_fetch_object($res_pack)){
fwrite($fp, "\n");
foreach ( $pack_row as $line ) {
$val = $line.',';
fwrite($fp, $val);}}
fclose($fp);}
Here column name as "external" and the value is joe,bob. In mysql table the value of external return as joe,bob, but in csv file it displayed as joe is in one column and bob is in another column.
Please refer the screenshot for CSV file. Csv file
fputcsv($fp, array('Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5'));wouldn't this work?str_getcsvphp.net/manual/en/function.str-getcsv.php And see related question: stackoverflow.com/questions/6536826/dealing-with-commas-in-csv