我的代码运行得很好,但它也打印出表格元素。我不知道如何解决它。谢谢
<?php
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=deferred_doc.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('APP NUMBER', 'SPOC ASSIGNED', 'BORROWER NAME', 'APP_FINISH_DATE','DEVELOPER & PROJECT', 'COLLATERAL ADDRESS DETAILS' ,'ORIGINAL_DEADLINE', 'DEFERRED TYPE','DEFERRED_DOCUMENT','SPOC REMARKS', 'JUW-MA REMARKS', 'COSU REMARKS','FILE LOCATION','SMU NOTES','DATE COMPLETED','SUBMITTED/PENDING','ID'));
// fetch the data
mysql_connect('xxxx', 'xxxx', 'xxx');
mysql_select_db('export_workflow');
$rows = mysql_query('SELECT * FROM COLLATERAL_MANAGEMENT');
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);
?>
csv 打印出这样的表格元素
最佳答案
我使用 my_sql 执行了错误的代码,应该使用 my_sqli 从数据库获取数据
关于php - 如何创建 csv 文件而不在文件中插入表格元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30228170/