You have to generate another array grouped by description or just query another SQL statement, that reads out the grouped rows. Since you have all the data queried already I 'd suggest a simple array grouped by description.
$grouped = [];
$data = mysqli_fetch_array($query);
foreach ($data as $row) {
if (!isset($grouped[$row['description'])) {
$grouped[$row['description]] = 0;
}
$grouped[$row['description'] += $row['amount'];
}
// process your templating here
foreach ($data as $row) {
...
}
Anayway ... another solution could be a simple SQL Statement.
SELECT SUM(amount) AS sum FROM table WHERE description_id = :description_id
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…