I reworked the code based on what I see in it and added a balance calculator, but I have not tested it.
<?php
$sql = "SELECT name, doc_date, descs, debit, credit
FROM statement
WHERE member_id = $member_id
ORDER BY doc_date";
$query = mysql_query($sql);
$combinedResults = array();
while ($result = mysql_fetch_array($query)) {
$combinedResults[$result['name']][] = array(
'name' => $result['name'],
'doc_date' => $result['doc_date'],
'descs' => $result['descs'],'debit' => $result['debit'],
'credit' => $result['credit']
);
}
$fmt = "<tr>\n <td>%s</td>\n <td>%s</td>\n <td>%s</td>\n <td>%s</td>\n <td>%s</td>\n</tr>";
print "<style type='text/css'>TD{width:105px;}</style>\n";
print "<table>\n";
foreach ($combinedResults[$groupKey] as $item) {
printf($fmt, "Date", "Description", "Debit", "Credit", "Balance");
printf($fmt, $groupKey, "", "", "", "");
$balance = 0;
foreach ($combinedResults[$groupKey] as $item) {
printf($fmt, $item['doc_date'], $item['descs'], $item['debit'], $item['credit'], "");
$balance += $item['debit'];
}
printf($fmt, "", "", "", "", $balance);
}
print "</table>\n";
I am interested to know if this works. :)
, "colspan"; , , .