I am pulling a set of numbers from a MySQL database and am trying to do some simple math on them to calculate a total price to put into an invoice, but PHP isn't cooperating. I thought it might be a type-coercion issue, so I tried adding some intval
and floatval
calls, but still the total always comes out to 0.
Here is the relevant code.
$totalSum = 0;
$parts = $db->select("*", "WHERE record_id=$id", "recordparts");
foreach($parts as &$part) {
$part['priceTotal'] = (floatval($part['price']) * intval($price['quantity'])) + (floatval($part['laborTime']) * floatval($price['laborRate']));
$totalSum += $part['priceTotal'];
}
$record['parts'] = $parts;
$record['partsSum'] = $totalSum;
And here are the results of the above operation
parts => Array (1)
0 => Array (8)
id => "18"
partNumber => "92-000001"
record_id => "17"
price => "11.5"
laborTime => "2"
laborRate => "65"
quantity => "1"
priceTotal => 0
partsSum => 0