Couple of things.. First of all, in order to be able to reliably access your
query field, you should name it:
<cfquery name="appendOne" datasource="dbusertracking">
SELECT Sum(contDuration) AS duration
FROM tb_contarea
WHERE contName = '#areas#'
</cfquery>
So that you can reliably refer to the column name in the resulting query -
different DBMSs will name it differently and I'd hate to have that change on me
when I upgraded or switched the database. Now instead of having a field named
"Sum(contDuration)" which is not a legal variable name, you have "duration"
which is.
Second thing.. Your queries by definition will contain only one row and one
column. Why bother with the hassle and added expense of the query's baggage in
your array? Instead of:
<cfset ArrayAppend(durations, appendOne)>
use:
<cfset ArrayAppend(durations, appendOne.duration)>
so you're only appending a number and not a query object.
Now the array returned will be more simplistic to deal with - you'll have an
array of numbers in result. You could then refer to them as result[0],
result[1]...result and those will be numbers. The way you have it now, result
is a query object.
If you have a situation where you really need an array of queries, you ust
need to address a little better. result[0] refers to the first query object in
your array. The query object has several properties that you can see in the
debugger output, the most interesting to us being _items. This is an array of
Objects which represent your rows. Your rows have only one column, so your row
Objects have only one property (which is called god knows what because the
column name isn't a legal variable name). If you had renamed the column as
"duration", the duration property in the first row of the first query in your
dump would be:
result[0]._items[0].DURATION
Note the upper-case as CF returns the column names in all upper-case.
Hopefully this helps (and I haven't made any typos or other mistakes).
sacal - 03 Aug 2005 18:05 GMT
THANK YOU SOOOOOOOOOOOOOOOOOOOOO MUCH!!! :beer;
I did figure out yesterday I was getting an object back from the server. So I
was using recursive loops to drill it down to the values I wanted. What a
pain!!!
But now! Thanks to you, all I get back is the array with the 4 values I want,
and nothing else! You're such a genius!
Thank you again for taking the time in reading, analyzing and responding to my
question! :-D