Anda salah. Anda bisa mendapatkan jumlahnya melalui pernyataan MySql itu sendiri.
Gunakan jumlah fungsi agregat bersama dengan kelompok demi klausa.
Seperti ini,
SELECT DebitAccount,sum(Account) from 2_1_journal group by DebitAccount
Kode lengkap Anda:
$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));
}
}