我需要在我的应用程序中将 db 内容导出为 csv 文件。它正在工作。但是内容不是从第一行开始的。它从第 40 行开始。我还需要做什么?
header('Content-Encoding: UTF-8');
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header('Content-Type: text/csv, charset=UTF-8; encoding=UTF-8');
$filename = date('Y_m_d_s');
header("Content-Disposition: attachment; filename=\"".$filename.".csv\"");
if($dbResult) {
$cnthead=0; $cntr =count($dbResult[0])-1;
foreach($dbResult[0] as $key => $Val){
echo $key;
if($cnthead < $cntr) {
echo ",";
$cnthead++;
}
}
echo "\n";
foreach($dbResult as $dbRes){
$cntcontnt=0;
foreach($dbRes as $dbVal){
echo $dbVal;
if($cntcontnt < $cntr) {
echo ",";
$cntcontnt++;
}
}
echo "\n";
}
}
$dbResult 数组如下所示,
Array
(
[0] => Array
(
[Appraisee Name] => aaa R
[Team] => Software
[Appraisee Emp No] => -
[Appraiser Name] => vvv A
[Appraiser Emp No] => -
[Reviewer Name] => sss S
[Reviewer Emp No] => -
[Current Appraisal Status] => start
)
[1] => Array
(
[Appraisee Name] => gan R
[Team] => Software
[Appraisee Emp No] => -
[Appraiser Name] => fcv R
[Appraiser Emp No] => -
[Reviewer Name] => sss S
[Reviewer Emp No] => -
[Current Appraisal Status] => start
)
)