的一個報表:
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 "
";echo "
門店 |
金額 |
"; while($row = mssql_fetch_array($result)) echo "
$row[0] |
$row[1] |
";echo "
";
回複討論(解決方案)
$total = array('合計', 0);while($row = mssql_fetch_array($result)) { echo "$row[0]$row[1]"; $total[1] += $row[1];}echo "$total[0]$rotal[1]";echo "";
$total = array('合計', 0);while($row = mssql_fetch_array($result)) { echo "$row[0]$row[1]"; $total[1] += $row[1];}echo "$total[0]$rotal[1]";echo "";
謝謝,正確了。新手還有好多函數需要學習!以後還有許多問題需要請教,再次感謝!