获取行和列的总和

发布于 2024-11-07 00:55:28 字数 408 浏览 1 评论 0 原文

到目前为止,我已经制作了一个包含产品及其总和的表格,根据一个月,我是这个方面的新手,所以我有一个错误:变量total2_1_27未定义。我无法按月获取产品的总和,到目前为止我发现是按行获取的,但无法按列获取...所以这里是代码: http://jsfiddle.net/Tskak/1/ 我只是不明白如何定义这总共2,这一行:

<cfset 'total2_#ddd_other#_#p_index#'=evaluate('total2_#ddd_other#_#p_index#') + #evaluate('alan2_#ddd_other#_#p_index#')#>

请有人帮忙!并感谢大家的帮助!

So far i have made a table with products and its sums, according to a months, i am a new in this so i have a mistake: Variable total2_1_27 is undefined. i cant get the sums of products by month, i found so far by a row but couldnt get by column... so here is the code:
http://jsfiddle.net/Tskak/1/ i just can't understand how do i define this total2, this line:

<cfset 'total2_#ddd_other#_#p_index#'=evaluate('total2_#ddd_other#_#p_index#') + #evaluate('alan2_#ddd_other#_#p_index#')#>

pls somebody help! and thank you all for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

树深时见影 2024-11-14 00:55:28

希望您使用的是 SQL Server 2005 或更高版本。由于使用了 DATEPART 函数,我假设您使用的是 SQL Server。我实际上会使用 SQL Server 中的 PIVOT 命令来解决您的问题按产品 ID 和月份列出总计列表,并将其转换为 CFQUERY 中的列。它将大大减少页面上的代码量,如果您在查询中进行总计,则应将代码减少到 CFQUERY,然后是一个简单的 CFOUTPUT/CFLOOP 围绕着桌子。它将删除您的所有列表和列表中的循环。将使这个页面成为编码的乐趣,而不是现在的头痛。

Hopefully you are on SQL Server 2005 or greater. I am assuming you are on SQL Server because of the use of the DATEPART function. I would actually tackle your problem using the PIVOT command in SQL Server to take your list of totals by product ID and month and convert them to columns in your CFQUERY. It will greatly reduce the amount of code on the page and if you do the totaling in the query should reduce the code down to the CFQUERY and then a simple CFOUTPUT/CFLOOP around the table. It will get rid of all your lists and loops within your lists. Will make this page a joy to code instead of the headache it is now.

葬シ愛 2024-11-14 00:55:28

不要在 cfset 中使用评估或将变量名称放在引号内,例如

而是像这样引用变量:

<cfset variables['total2_#ddd_other#_#p_index#'] = variables['total2_#ddd_other#_#p_index#'] + variables['alan2_#ddd_other#_#p_index#']>

<cfset variables['total2_' & ddd_other & '_' & p_index] = variables['total2_' & ddd_other & '_' & p_index] + variables['alan2_' & ddd_other & '_' & p_index]>

这是假设该值在变量范围内。如果它在会话范围内,您将引用它 session['total2_' & ddd_other & '_' & p_index]。您还可以在 CF8 和 CF9 中使用 +=,这样就可以了:

<cfset variables['total2_' & ddd_other & '_' & p_index] += variables['alan2_' & ddd_other & '_' & p_index]>

Don't use evaluate or put variable names inside quotes in a cfset like <cfset 'blah_#x#' = foo>.

Instead refer to variables like this:

<cfset variables['total2_#ddd_other#_#p_index#'] = variables['total2_#ddd_other#_#p_index#'] + variables['alan2_#ddd_other#_#p_index#']>

or

<cfset variables['total2_' & ddd_other & '_' & p_index] = variables['total2_' & ddd_other & '_' & p_index] + variables['alan2_' & ddd_other & '_' & p_index]>

This is assuming that the value is in the variables scope. If it was in say session scope you'd refer to it session['total2_' & ddd_other & '_' & p_index]. Also you can use += in CF8 and CF9, so this would be fine:

<cfset variables['total2_' & ddd_other & '_' & p_index] += variables['alan2_' & ddd_other & '_' & p_index]>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文