今天做了一個匯出csv,程式碼非常簡單
$result = $list;
$str = "下單時間,酒店名稱,聯絡人,預約次數,聯絡人電話,房型,房間價格,押金,訂房數量,入住,離店,狀態,支付方式\n";
foreach ($result as $value) {
$temp = "\t".date('Y-m-d H:i:s',$value['time']) . ','.$value['seller_name']. ','.$value['name']. ','.$value['count']. ','."\t".$value['tel']. ','.$value['room_type']. ','.$value['price']. ','.$value['yj_cost']. ','.$value['num']. ','."\t".substr($value['arrival_time'],0,10). ','."\t".substr($value['departure_time'],0,10). ','.sn_status($value['status']).','.pay_type($value['type'])."\n";
$str .= $temp;
}
$filename = '訂單資料'.date('Ymd').'.csv';
header("Content-type:text/csv");
header("Content-type:application/vnd.ms-excel" );
header("Content-Disposition:attachment;filename=".$filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo $str;
exit;
本作品採用《CC 協議》,轉載必須註明作者和本文連結