> Can someone suggest a better way to sum a numeric column in a query? The
> solution is probably painfully simple, but I've been struggling
> for an hour or two on it (only have online docs available).
>
> <CFOUTPUT>#ArrayDeleteAt(GetHours,1)#</CFOUTPUT>
> <CFLOOP query="getMainList">
>    <CFOUTPUT>#ArrayAppend(GetHours, "#numberformat(hours)#")#</CFOUTPUT>
> </CFLOOP>
>
> Line 3 produces a string of "YES"s at the top of my output- one for every
> record in the query.
>
> The following gives me the result I need, but I can't get around the
> display of the YES's that appears.
>
> <cfset cost = ArraySum(GetHours)*65>
> <CFOUTPUT>
>     <P>The sum of the numbers is #ArraySum(GetHours)# hours. At $65/hr,
> this equals #dollarformat(cost)#
> </CFOUTPUT>

OK, first off, it's a function so set it to a variable;
tmpVar=ArrayAppend(GetHours, numberformat(hours))

Second off, don't do a CFOutput unless you WANT the output to the browser

Third off, please read Ben Forta's article "To # or not to #"

Fourth off, if you're using CF4.5.1SP2, use CFScript
<cfscript>
ArrayDeleteAt(GetHours,1)
for (i=1; i lte getMainList.recordCount; i=i+1)
        ArrayAppend(GetHours, numberformat(getMainList.hours[i]));
</cfscript>

Philip Arnold
Director
Certified ColdFusion Developer
ASP Multimedia Limited
T: +44 (0)20 8680 1133

"Websites for the real world"

**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to