[英]somebody can help me to align CSV document while downloading
I have written a PHP code to download reports as a CSV file format. 我已经编写了PHP代码,以CSV文件格式下载报告。 But the thing i need to do is, I need to align If the DIDNo having 2 or more AgentNumber then i need to put it by side 但是我需要做的是,我需要对齐如果DIDNo具有2个或更多的AgentNumber,那么我需要将其并排放置
ex:
DIDNo AgentNumber
001 12334554 12334578 1234556
<?php
require_once('common.php');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('DIDNo','AgentNumber'));
// fetch the data
$sql = "SELECT didNo,agentNumber FROM AGENT_INFO";
$rows = mysql_query($sql);
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);
?>
I am getting:
--------------------------------------------------
DIDNo AgentNumber
3054001 994740040
3054002 994734911
3054002 908799144
3054003 999497774
3054003 960007775
3054004 442853588
3054004 999470955
3054004 960044599
3054005 999458354
3054005 814461211
DIDNo AgentNumber
3054001 999440040
3054002 999434911 908799944
3054002
3054003 999497774 960007775
3054003
3054004 442853588 999470955 960044599
3054004
3054004
3054005 999458354 814461211
3054005
$sql = "SELECT didNo,
GROUP_CONCAT(agentNumber SEPARATOR ',') as agentNumbers
FROM AGENT_INFO
GROUP BY didNo";
$rows = mysql_query($sql);
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) {
$data = array();
foreach($row as $value) {
$data = array_merge($data, explode(',', $value));
}
fputcsv($output, $data);
}
(untested) (未试)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.