Coldfusion计算总和(循环?) [英] Coldfusion Calculate Sum Total (Loop? )
本文介绍了Coldfusion计算总和(循环?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的.所以我有这张桌子:
ok. so i have this table:
|项目|数量|价格|
|苹果|2 |2.00 |
|橙色 |3 |1.50 |
|葡萄 |5 |2.50 |
|apple | 2 | 2.00 |
|orange | 3 | 1.50 |
|grape | 5 | 2.50 |
我想显示客户必须支付的总计.怎么做?在此输入代码
我真的不知道如何使用数组.谁能告诉我怎么做?
i want to display the Grand Total that a customer has to pay.
how to do that? enter code here
i don't really know how to use array. can anyone show me how?
我的代码(有点)
价格显示在使用此查询的每一行中:
the price is shown in each of the row using this query:
<cfquery name="getPrice" datasource="fruits">
select *
from fruits
</cfquery>
<cfloop query="getPrice">
#quantity# | #price# | #totalPrice#
</cfloop><br>
总计应显示在最后一行(总计 =$ 21.00).
the Grand Total should be displayed in the last row (Grand Total =$ 21.00 ).
感谢您的帮助.
推荐答案
<cfset grandTotal = 0 />
<cfloop query="getPrice">
#quantity# | #price# | #totalPrice#<br />
<cfset grandTotal = grandTotal + ( price * quantity ) />
</cfloop>
<br /><br />
<cfoutput>#grandTotal#</cfoutput>
这篇关于Coldfusion计算总和(循环?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文