我有一个包含4个字段的表我正在查询。我试图把查询放到一个csv指针,我正在对列和行进行抽象格式化。
我回到了第一行:
Status,Account,PO,Field,1000,2112,HTWC2112,Booyah,1000,877,HTWC4293,Booyah
我想:
Status,Account,PO,Field`
1000,2112,HTWC2112,Booyah
1000,877,HTWC4293,Booyah
1000,877,HTWC42870,Booyah
以下是我的目标:
<?php
require('db.php');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
ob_end_clean();
$output = fopen('php://output', 'w');
$array = array('Status','Account', 'PO', 'Field');
fputcsv($output, $array, ',');
$rows = mysqli_query($con, 'SELECT * FROM TestCSVImport');
while ($row = mysqli_fetch_assoc($rows))
{
fputcsv($output, $row,',');
}
mysqli_close($con);