Du går forkert om det. Du kan få summen gennem selve MySql-erklæringen.
Brug aggregeringsfunktionen sum sammen med gruppe efter klausul.
Sådan,
SELECT DebitAccount,sum(Account) from 2_1_journal group by DebitAccount
Din fulde kode:
$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));
}
}