0

I'm simply trying to add two decimal numbers which are dynamic variables retrieved from a database.

Using bcadd works fine, but only if the parameters are not in the form of variables. See code below.

I've tested the two variables and they output the correct values, so the issue is not with the variables themselves.

Any help would be really appreciated.

<?php

include 'config.php';

$sqlogu = "SELECT oq_takeoff, oq_uplift FROM tbl_flights WHERE aircraft_id = 1 ORDER BY flight_id DESC LIMIT 1;";

$resultGU = $conn->query($sqlogu);

while ($rowGU = $resultGU->fetch_assoc()) { 

    $oq_takeoff_gu = $rowGU['oq_takeoff'];
    $oq_uplift_gu = $rowGU['oq_uplift'];

$ac_oil_gu = number_format($oq_takeoff + $oq_uplift, 2);

$test  = bcadd(2.00, 6.00, 2); // produces 8.00
$test2 = bcadd($oq_takeoff, $oq_uplift, 2); // produces 0.00

echo "Takeoff: " . $oq_takeoff_gu . "<br/>";
echo "Uplift: " . $oq_uplift_gu . "<br/>";
echo "Total: " . $ac_oil_gu . "<br/>";
echo "Test: " . $test;
echo "Test 2: " . $test2;

}
sinesine
  • 183
  • 1
  • 11

1 Answers1

2

your

bcadd($oq_takeoff, $oq_uplift, 2)

isn't defined anywhere so it will always be zero, you might have forgot the_gu on the end of them

ATechGuy
  • 1,240
  • 8
  • 13