這裏的任何人都可以幫我解決這個問題嗎?我只想得到某一欄的總數或總和,請參考下圖。一直試圖排序這2天,但不能 得不到運氣,希望任何人都可以幫助我這一點。我非常感謝,並在 提前感謝。數組列總和
這裏是一個示例圖像http://www.freeimagehosting.net/pig81
<?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`]);}
foreach(array_keys($combinedResults) as $groupKey) { ?>
<table>
<tr><?php foreach($combinedResults[$groupKey] as $item) {?>
<td>Date</td>
<td>Description</td>
<td>Debit</td>
<td>Credit</td>
<td>Balance</td>
</tr>
<tr>
<td colspan="2"><?php echo $groupKey; ?></td>
<td width="105"> </td>
<td width="105"> </td>
<td width="105"> </td>
</tr>
<tr><?php foreach($combinedResults[$groupKey] as $item) {?>
<td><?php echo $item[`doc_date`];?></td>
<td><?php echo $item[`descs`];?></td>
<td><?php echo $item[`debit`];?></td>
<td><?php echo $item[`credit`]; ?></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>sum of debit goes here</td>
</tr>
<?php }} ?>
</table>
嗨ghoti,感謝您的答覆。我認爲它的工作,但它只需要一點點調整,因爲它根據項目數量循環或顯示多個結果。這裏是示例輸出http://www.freeimagehosting.net/xx7bc – 2012-04-29 17:31:58
嗨ghoti,它再次。它的工作現在,非常感謝您的時間和幫助..非常感謝。 – 2012-04-29 18:21:43
沒問題。感謝您的支持。 – ghoti 2012-05-01 18:26:54