我創建了一個網站,根據用戶搜索顯示記錄。但是,我想讓用戶選擇將獲取的記錄下載為 csv 檔案。如何使用 JavaScript 將獲取的 MySQL 資料匯出為 CSV?
uj5u.com熱心網友回復:
使用資料表,這里是一個例子 https://datatables.net/extensions/buttons/examples/initialisation/export.html
uj5u.com熱心網友回復:
<?php
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=\"report".".csv\"");
header("Pragma: no-cache");
header("Expires: 0");
$handle = fopen('php://output', 'w');
fputcsv($handle, array("SNo","Complain_id","Name","Email","Number","Address"));
$cnt=1;
foreach ($complains as $key) {
$cnt ;
$narray=array($cnt,$key->fld_complain_id,$key->fld_customer_name,$key->fld_customer_email,$key->fld_customer_number,$key->fld_customer_address,);
fputcsv($handle, $narray);
}
fclose($handle);
exit;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/367445.html
標籤:javascript php mysqli
下一篇:如何使用js將字串拆分為陣列
