Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
<?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];
?>

This function worked previously being single blocks of code. Now I tried changing it to a generic function. No errors are produced. The output array of the function seems empty.

share|improve this question

closed as off-topic by Jack, Touki, RiggsFolly, Mark Rotteveel, zishe Jun 18 at 10:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Jack, Touki, RiggsFolly, Mark Rotteveel, zishe
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
You sure your queries are running correctly? Do you have error reporting on (ini_set('display_errors', 1); error_reporting(E_ALL);) ? –  Darren Jun 18 at 6:59

1 Answer 1

up vote 1 down vote accepted

You are not storing output of function call to anywhere and trying to do echo.

You should store returned output to some variable ( let say, $calculateTotals) and then do echo

echo "TEST CALC";
$calculateTotals = calculateTotals("timePIC","1","100","0");
echo $calculateTotals[0];

This should work.

share|improve this answer
    
Many thanks! That solved it, off course! –  N34X Jun 18 at 7:08
    
Most welcome dude.. then don't forgot to mark it as answer. :) –  Log1c ツ Jun 18 at 7:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.