I have a prepared statement that produces a list of prices. The prices are determined by the value of the item multiplied by the quantity.
if ($select = $db -> prepare("SELECT value, quantity FROM items"))
{
$select -> execute();
$select -> bind_result($value, $quantity);
while ($select -> fetch())
{
$subtotal = $value * $quantity;
echo $subtotal.'<br />';
}
$select -> close();
}
// I want to put the $total here.
This outputs a list of numbers:
100
50
200
1.50
I would like to somehow add up each $subtotal and put them into another variable "$total" outside of my prepared statement. Is this possible to do WITHOUT doing the math within the query?