• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Finding the average value of related structure keys

Participant ,
Feb 13, 2007 Feb 13, 2007

Copy link to clipboard

Copied

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
8 RES_ROOM3_ADULTS
9 RES_ROOM3_MINORS
10 RES_ROOM1_ADULTS
11 RES_ROOM2_ADULTS
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?
TOPICS
Advanced techniques

Views

252

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2007 Feb 13, 2007

Copy link to clipboard

Copied

Loop over all the keys and use string processing on each key to
determine which type it is, then process accordingly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 13, 2007 Feb 13, 2007

Copy link to clipboard

Copied

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. ;-)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 14, 2007 Feb 14, 2007

Copy link to clipboard

Copied

LATEST
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">
<cfif field contains "AGE|MINORS|ADULTS|Ect">
process
</cfif>
</cfloop>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation