3 Replies Latest reply on Feb 14, 2007 7:08 AM by Newsgroup_User

# Finding the average value of related structure keys

Issue:
I have a form structure which I need to find the value averages of all the *AGE keys, *MINORS keys, and *ADULTS keys.

Here's my example form structure, after using structkeyarray() of coarse:
1 RES_ROOM2_MINOR3_AGE
2 RES_ROOM1_MINORS
3 RES_ROOM2_MINOR1_AGE
4 RES_ROOM1_MINOR2_AGE
5 RES_ROOM3_MINOR1_AGE
6 RES_ROOM2_MINORS
7 RES_ROOM3_MINOR2_AGE
9 RES_ROOM3_MINORS
12 RES_ROOM1_MINOR1_AGE
13 RES_ROOM2_MINOR2_AGE

Question:
How should I AT LEAST go about pulling out each set of keys so i can procede to find the mean?
• ###### 1. Re: Finding the average value of related structure keys
Loop over all the keys and use string processing on each key to
determine which type it is, then process accordingly.
• ###### 2. Re: Finding the average value of related structure keys
Such as...

cfset keys = structkeylist (form)
- cfloop index='x' list='keys'
- - cfif x contains AGE/MINORS/ADULTS blah
- - cfset blah
- /cfloop

... ?

I guess that should definately work. Simple no less. I got caught up looking for a special function to run through the structure. Thanks for shaking my head up, and sending me on my way. ;-)
• ###### 3. Re: Finding the average value of related structure keys
Such as...

cfset keys = structkeylist (form)
- cfloop index='x' list='keys'
- - cfif x contains AGE/MINORS/ADULTS blah
- - cfset blah
- /cfloop

... ?

I guess that should definitely work. Simple no less. I got caught up
looking for a special function to run through the structure. Thanks for
shaking my head up, and sending me on my way. ;-)

That's the idea. If you care, you can use the collection form of the
<cfloop...> tag. Eliminates the need to pull out the list of keys
separately.

<cfloop collection="#form#" item="field">