开发者

Get sum of a row and column

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 开发者_如何学Pythonfar 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!


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.


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]>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜