我有一个php脚本,可以创建一个带有2个工作表的excel文件。第一张表是完美的,因为它为各个用户的记录制定了值,所以我使用了一个关联数组,使用他们的用户ID作为索引。
第二张表只获得部门总计5天,而不是说"对于每个ID创建一个记录数组并在该记录上制定"我想说"将所有5行作为一个记录组加载到数组中,这样我就可以仅基于那些记录来制定"。我希望这是有道理的。
我的脚本现在的方式是,它在所有5条记录之间放置我的配方行(平均值,中位数和模式),但我只需要在所有5条记录之后的一个配方行。基本上我现在只是循环太多而且我不知道在哪里重构它。
这是脚本:
$resultData2 = array();
while($row2 = mysqli_fetch_assoc($result2))
{
$resultData2[$row2['TalkTime']][] = $row2;
}
//Set starting row number
$rowNo2 = 1;
// //Iterate over the results for each unique id
foreach($resultData2 as $idRecords2)
{
$userFirstRow2 = $rowNo2+1;
//Iterate over the records for this ID
foreach($idRecords2 as $record2)
{
//Increment row number
$rowNo2++;
//Add record row to spreadsheet
$worksheet1->setCellValue("A{$rowNo2}", $record2['TalkTime']);
$worksheet1->setCellValue("D{$rowNo2}", $record2['Outbound']);
$worksheet1->setCellValue("G{$rowNo2}", $record2['Inbound']);
$worksheet1->setCellValue("J{$rowNo2}", $record2['Dealers']);
$worksheet1->setCellValue("M{$rowNo2}", $record2['Date']);
$worksheet1->setCellValue("N{$rowNo2}", $record2['Day']);
}
//Increment row number
$rowNo2++;
$worksheet1->setCellValue("A{$rowNo2}", "Mean");
$worksheet1->setCellValue("B{$rowNo2}", "Median");
$worksheet1->setCellValue("C{$rowNo2}", "Mode");
$worksheet1->setCellValue("D{$rowNo2}", "Mean");
$worksheet1->setCellValue("E{$rowNo2}", "Median");
$worksheet1->setCellValue("F{$rowNo2}", "Mode");
$worksheet1->setCellValue("G{$rowNo2}", "Mean");
$worksheet1->setCellValue("H{$rowNo2}", "Median");
$worksheet1->setCellValue("I{$rowNo2}", "Mode");
$worksheet1->setCellValue("J{$rowNo2}", "Mean");
$worksheet1->setCellValue("K{$rowNo2}", "Median");
$worksheet1->setCellValue("L{$rowNo2}", "Mode");
$rowNo++;
}