Home >Backend Development >PHP Tutorial >关于PHP结合html表格查询数据汇总行或列的问题

关于PHP结合html表格查询数据汇总行或列的问题

WBOY
WBOYOriginal
2016-06-23 13:46:441175browse

如图的一个报表:


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>";




谢谢,正确了。新手还有好多函数需要学习!以后还有许多问题需要请教,再次感谢!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn