Je gaat er verkeerd mee om. Je kunt de som krijgen via het MySql-statement zelf.
Gebruik de aggregatiefunctie som samen met group by clausule.
Zoals dit,
SELECT DebitAccount,sum(Account) from 2_1_journal group by DebitAccount
Uw volledige code:
$query = " SELECT DebitAccount,sum(Account) as Total from 2_1_journal group by DebitAccount";
$sql = $db->prepare($query);
$sql->execute();
$data = $sql->fetchAll(PDO::FETCH_ASSOC);
foreach($data as $result){
if(strlen($result['Total']) > 0 ) {
echo "DebitAccount ". $result['DebitAccount']. "Total is: ". $result['Total']. "<br>";
print_r (array_sum($result));
}
}