<?php
function calculateTotals($column,$rowStart,$rowEnd,$boolSim) {
$queryTotalPage = "SELECT SUM(`" . $column . "`) FROM `mylogbook` WHERE `flightNumber` >= " . $rowStart . " AND `flightNumber` <= " . $rowEnd . " AND `simulator` = " . $boolSim;
$resultTotalPage = mysql_query($queryTotalPage) or die(mysql_error());
while($row = mysql_fetch_array($resultTotalPage)){
$totalTimeHoursPage = floor($row["SUM(" . $column . ")"]/60);
$totalTimeMinutesPage = sprintf('%02d', ($row["SUM(" . $column . ")"] % 60));
}
$queryTotalPreviousPages = "SELECT SUM(`" . $column . "`) FROM `mylogbook` WHERE `flightNumber` >= 1 AND `flightNumber` < " . $rowStart . " AND `simulator` = " . $boolSim;
$resultTotalPreviousPages = mysql_query($queryTotalPreviousPages) or die(mysql_error());
while($row = mysql_fetch_array($resultTotalPreviousPages)){
$totalTimeHoursPreviousPages = floor($row["SUM(" . $column . ")"]/60);
$totalTimeMinutesPreviousPages = sprintf('%02d', ($row["SUM(" . $column . ")"] % 60));
}
$queryTotal = "SELECT SUM(`" . $column . "`) FROM `mylogbook` WHERE `flightNumber` >= 1 AND `flightNumber` <= " . $rowEnd . " AND `simulator` = " . $boolSim;
$resultTotal = mysql_query($queryTotal) or die(mysql_error());
while($row = mysql_fetch_array($resultTotal)){
$totalTimeHours = floor($row["SUM(" . $column . ")"]/60);
$totalTimeMinutes = sprintf('%02d', ($row["SUM(" . $column . ")"] % 60));
}
return array($totalTimeHoursPage,$totalTimeMinutesPage,$totalTimeHoursPreviousPages,$totalTimeMinutesPreviousPages,$totalTimeHours,$totalTimeMinutes);
}
// TEST calculate totals
echo "TEST CALC";
calculateTotals("timePIC","1","100","0");
echo $calculateTotals[0];
?>
此功能以前是单块代码。现在我尝试将其更改为通用函数。没有错误产生。函数的输出数组似乎是空的。
答案 0 :(得分:1)
您没有将函数调用的输出存储到任何地方并尝试执行echo
。
您应该将返回的输出存储到某个变量(比如$calculateTotals
),然后执行echo
echo "TEST CALC";
$calculateTotals = calculateTotals("timePIC","1","100","0");
echo $calculateTotals[0];
这应该有用。