如何将 csv 数据分成两部分。?
How to split csv data in two parts.?
是否可以将 csv 数据导出为两部分:
从下图中我有两件事要考虑
1. 夏天的
2. 详细信息
我只用过第二种类型,可以做 2 批吗(如图所示)..?
如果你有任何替代想法,请提出。
示例:
总结header
$titleSummery = array('Course Name','Average watched','semi watched','notwached','sudents attempted','sudents notattempted','Total students','Branch','passout');
/*summery data */
详情header
$titleDetail = array('student','passout','branch','percentage watched','student email');
/*Details data */
In this case how can i export the data..?
$output = fopen('php://output', 'w');
fputcsv($output, $title);
foreach($data as $k=>$res){
fputcsv($output,$res);
}
你的方向很好,你只需要明白每次调用fputcsv都会打印一行,所以你也需要为第一批数据中的每一行调用它,例如:
fputcsv($output,"course name","php for dummies");
您需要为每一行准备数组。查看我的内嵌评论。
$titleSummery = array('Course Name','Average watched','semi watched','notwached','sudents attempted','sudents notattempted','Total students','Branch','passout');
$titleSummeryData = array('Number System','50%','40%',....); // fill remaining data.
$output = fopen('php://output', 'w');
// put first table
foreach($titleSummery as $key=>$val){
fputcsv($output,array($val,$titleSummeryData[$key]));
}
// begin second table
// put all title/header
fputcsv($output,$titleDetail);
// For second table i assume that you have data in 2D array
foreach($titleDetailsData as $row){
fputcsv($output);
}
fclose($output);
是否可以将 csv 数据导出为两部分:
从下图中我有两件事要考虑 1. 夏天的 2. 详细信息
我只用过第二种类型,可以做 2 批吗(如图所示)..?
如果你有任何替代想法,请提出。
示例:
总结header
$titleSummery = array('Course Name','Average watched','semi watched','notwached','sudents attempted','sudents notattempted','Total students','Branch','passout');
/*summery data */
详情header
$titleDetail = array('student','passout','branch','percentage watched','student email');
/*Details data */
In this case how can i export the data..?
$output = fopen('php://output', 'w');
fputcsv($output, $title);
foreach($data as $k=>$res){
fputcsv($output,$res);
}
你的方向很好,你只需要明白每次调用fputcsv都会打印一行,所以你也需要为第一批数据中的每一行调用它,例如:
fputcsv($output,"course name","php for dummies");
您需要为每一行准备数组。查看我的内嵌评论。
$titleSummery = array('Course Name','Average watched','semi watched','notwached','sudents attempted','sudents notattempted','Total students','Branch','passout');
$titleSummeryData = array('Number System','50%','40%',....); // fill remaining data.
$output = fopen('php://output', 'w');
// put first table
foreach($titleSummery as $key=>$val){
fputcsv($output,array($val,$titleSummeryData[$key]));
}
// begin second table
// put all title/header
fputcsv($output,$titleDetail);
// For second table i assume that you have data in 2D array
foreach($titleDetailsData as $row){
fputcsv($output);
}
fclose($output);