我有 tbl_building、tbl_rooms、tbl_lighting 等表。
每个都有自己的元组,因此可以有许多建筑物、建筑物内的许多房间以及房间内的许多照明项目。这是通过为每个建筑物/房间/照明提供自己的 ID 来构建的。
我要完成的任务之一是在 Excel 电子表格中为每个建筑物内的每个房间显示灯光列表。
这是我的代码。这显然是错误的,但我无法理解输出数据。
function getLights($buildingID, $d, $objPHPExcel, $status){
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], 'Please Enter Hours Of Usage: ');
include("setText.php");$status[2]++;
$groupStart = $status[1].$status[2];
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], 'Lights Used:');
$status[1]++;
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], 'Count');
$status[1]++;
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], 'kWh/yr');
$status[1]++;
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], 'Energy Saving kWh/yr');
$status[1]++;
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], 'Saving(£)');
$status[1]++;
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], 'Cost');
$status[1]++;
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], 'Change To...');
$groupEnd = $status[1].$status[2];
include("setHeadersText.php");groupFill($objPHPExcel, $groupStart, $groupEnd, "calc");
$status[2]++;$status[1] = chr(65);
$query = "SELECT r_id FROM tbl_roomDesc WHERE b_id = '$buildingID'";
$result = $d->query($query);
$rooms = array();
array_push($rooms, 2);//echo "<br/>".$row['r_id'];
//echo "<br/>Building:";
/*while($row = $result->fetchArray(SQLITE3_ASSOC)){
array_push($rooms, $row['r_id']);//echo "<br/>".$row['r_id'];
}*/
//echo "<br/>";
//var_dump($rooms);
$lightArray = array(
"CFL",
"CFL Equivalent Halogen 100w spot",
"CFL Equivalent Halogen 50w spot",
"Double d",
"Halogen 100w spot",
"Halogen 50w spot",
"PL",
"T12 Single 4ft",
"T12 Single 5ft",
"T12 Single 6ft",
"T12 Single 8ft",
"T12 Twin 4ft",
"T12 Twin 5ft",
"T12 Twin 6ft",
"T12 Twin 8ft",
"T5 Quad 2ft",
"T5 Quad 4ft",
"T5 Single 4ft",
"T5 Single 5ft",
"T5 Triple 2ft",
"T5 Triple 4ft",
"T5 Triple 5ft",
"T5 Twin 2ft",
"T5 Twin 4ft",
"T5 Twin 5ft",
"T8 Quad 2ft",
"T8 Quad 4ft",
"T8 Single 4ft",
"T8 Single 5ft",
"T8 Single 6ft",
"T8 Twin 2ft",
"T8 Twin 4ft",
"T8 Twin 5ft",
"T8 Twin 6ft",
"Tungsten 60w",
"Other"
);
//echo sizeof($lightArray);
//for each room, get quant wattage and hours of each light referenced by the room id
echo sizeOf($rooms);
echo "<br/>";
for($i=0; $i<sizeof($rooms);$i++){
//set empty arrays
$size = 36;
$lightQuantityCount = array_fill(0, $size, 0);
$lightWattageCount = array_fill(0, $size, 0);
$lightHoursCount = array_fill(0, $size, 0);
//get all lighting data of particular room
$query2 = "SELECT * FROM tbl_lightingData WHERE r_id = '$rooms[$i]'";
$result2 = $d->query($query2);
$row2= $result2->fetchArray(SQLITE3_ASSOC);
//for each light type in the lightarray chechk if light type from query == light type in array, if so add quantity, wattage and hours to arrays
while($row2=$result2->fetchArray(SQLITE3_ASSOC)){
echo "<br/>Room ID: ".$rooms[$i]."<br/>";
$lightID = $row2['l_id'];
$lightType = $row2['lightType'];
$lightQuantity = $row2['lightQuantity'];
$lightWattage = $row2['lightWattage'];
$lightHours = $row2['lightHours'];
echo "Light Profile:<br/>Light ID: ".$lightID."<br/>Light Type: ".$lightType."<br/>Light Wattage: ".$lightWattage."<br/>Light Hours: ".$lightHours."<br/>";
for($j=0; $j<sizeof($lightArray); $j++){
if($lightType == $lightArray[$j]){
echo "<br/>MATCH<br/>";
$lightQuantityCount[$j] = $lightQuantityCount[$j] + $lightQuantity;
$lightWattageCount[$j] = $lightWattage;
$lightHoursCount[$j] = $lightHoursCount[$j] + $lightHours;
}
else{
echo "<br/>NO MATCH<br/>";
}
}
}
//echo"<br/>ARRAY DUMP START:<br/>";
//var_dump($lightQuantityCount);
//echo"<br/>ARRAY DUMP END:<br/><br/>";
echo "<br/>ADFSDFADFA : ".sizeof($lightQuantityCount);
echo "<br/>ADFSDFADFA : ";
for($k=0; $k<sizeof($lightQuantityCount); $k++){
if($lightQuantityCount[$k] != 0){
echo "<br/>Light Type: ".$lightArray[$k]."<br/>";
echo "Light Quantity Count: ".$lightQuantityCount[$k]."<br/>";
echo "Wattage Count: ".$lightWattageCount[$k]."<br/>";
echo "Hours Count: ".$lightQuantityCount[$k]."<br/>";
include("setText.php");$status[2]++;
$groupStart = $status[1].$status[2];
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], $lightArray[$k]);
$status[1]++;
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], $lightQuantityCount[$k]);
$status[1]++;
$calc = $lightWattageCount[$k] * $lightQuantityCount[$k];
$calc2 = $calc / 1000;
$objPHPExcel->getActiveSheet()->setCellValue($status[1].$status[2], $calc2);
$groupEnd = $status[1].$status[2];
include("setHeadersText.php");groupFill($objPHPExcel, $groupStart, $groupEnd, "calc");
$status[2]++;$status[1] = chr(65);
}
}
}
return $status;
}
评论获取更多信息,谢谢
克里斯