如图的一个报表:
PHP从mssql读取数据,合计行用什么方式求出。
这是部份代码,比如要求金额一列的合计,在表的最后一行显示合计以什么方式显示出并计算,谢谢各位老手指教!!
$query = "Select top 35 A.Branchdesc,sum(B.Amount)totalFrom BaseBranch A Inner Join Retail B On A.BranchID=B.BranchIDWhere B.DoneFlag=1 and B.DelFlag=0 and RetailType<>1 and Convert(varchar(12),B.WorkDate,112)='$searchdata'Group by A.Branchdesc order by total desc";$result = mssql_query($query); echo "$searchdata 的销售为:";echo "<table cellpadding=3>";echo "<tr bgcolor=#CCCCCC><td>门店</td><td>金额</td></tr>"; while($row = mssql_fetch_array($result)) echo "<tr><td>$row[0]</td><td>$row[1]</td></tr>";echo "</table>";
$total = array('合计', 0);while($row = mssql_fetch_array($result)) { echo "<tr><td>$row[0]</td><td>$row[1]</td></tr>"; $total[1] += $row[1];}echo "<tr><td>$total[0]</td><td>$rotal[1]</td></tr>";echo "</table>";
$total = array('合计', 0);while($row = mssql_fetch_array($result)) { echo "<tr><td>$row[0]</td><td>$row[1]</td></tr>"; $total[1] += $row[1];}echo "<tr><td>$total[0]</td><td>$rotal[1]</td></tr>";echo "</table>";