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