0

Looping over a Query Set as an Array

ColdFusion

One day, not too long ago, my buddy Fro showed me a cool way to sum up values of a query set using the arraySum function in ColdFusion. Say you have a query that returns all of your baseball cards and their respective values.  Well in this example you can do something like this

arraySum(qGetCards['cardValue']) 

That function will sum up all of the "cardValue" values returned from the query.

What I ran into today was the fact that I didn't want to add up all the values, just part of them.  For this I wrote the following script.  It is looping through a query and only summing the amount where there is no expirationDate. 

Hope this helps someone, somewhere!

Good Day,
Ryan

tags:
ColdFusion
 
I Scorpiofied it just for fun. :)

http://codeshare.ulatu.com/mayb68af
 
posted 600 days ago
Add Comment Reply to: this comment OR this thread
 
 
is this the only difference??

variables.currentTotal += sqlQry['amount'][i];
 
posted 600 days ago
Add Comment Reply to: this comment OR this thread
 
 
No, I altered the conditional statment too:
(i=1;i<=arrayLen(sqlQry['amount']);i++)

I know it is silly, but that syntax is one of the things I am most excited about!
 
posted 600 days ago
Add Comment Reply to: this comment OR this thread
 
 
ohh right, the <= instead of the LTE... but what about this line, can I use this line in my current code? With the += in there?

variables.currentTotal += sqlQry['amount'][i];
 
posted 600 days ago
Add Comment Reply to: this comment OR this thread
 
 
Not till Scorpio! Nor can you use the i++ at the end of the loop definition.
 
posted 600 days ago
Add Comment Reply to: this comment OR this thread
 

Search