Adobe Community
All community
This category
This board
Knowledge base
Users
cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results forÂ
ShowÂ
 onlyÂ
|
Search instead forÂ
Did you mean:Â
Global community
Language:
Deutsch
English
Español
Français
Português
日本語コミュニティ
Dedicated community for Japanese speakers
í•œêµ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Sign In
Exit
Home
ColdFusion
Discussions
Looping and setting cfset values (from a query)
Home
ColdFusion
Discussions
Looping and setting cfset values (from a query)
0
Upvote
Looping and setting cfset values (from a query)
Guest
/t5/coldfusion-discussions/looping-and-setting-cfset-values-from-a-query/td-p/323120
Aug 24, 2007
Aug 24, 2007
Copy link to clipboard
Copied
Stuck on how to get this to work.
How would I go about looping and setting these values instead of doing them individually?
The query this <cfset> references works fine and will work but repeats...
<cfset ans1 = (qryGetPcts1.q1Ct / qryGetCounts.qID2) * 100>
<cfset ans2 = (qryGetPcts2.q2Ct / qryGetCounts.qID2) * 100>
<cfset ans3 = (qryGetPcts3.q3Ct / qryGetCounts.qID2) * 100>
<cfset ans4 = (qryGetPcts4.q4Ct / qryGetCounts.qID2) * 100>
<cfset ans5 = (qryGetPcts5.q5Ct / qryGetCounts.qID2) * 100>
So I'd like to loop and set them all instead...
<cfloop index="i" from="1" to="27">
<cfset ans#i# = (qryGetPcts#i#.q#i#Ct / qryGetCounts.qID2) * 100>
</cfloop>
But it's responding with this...
Invalid CFML construct found on line 196 at column 19.
ColdFusion was looking at the following text:
#
I'm sure I'm missing something simple b/c this must be possible? Can I use a cfset in a loop?
Help is appreciated
TOPICS
Advanced techniques
Views
330
Translate
Translate
Report
Report
Follow
Report
More
Reply
Reply
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
5 Replies
5
Jump to latest reply
Dan_Bracuk
LEGEND
,
/t5/coldfusion-discussions/looping-and-setting-cfset-values-from-a-query/m-p/323121#M29204
Aug 24, 2007
Aug 24, 2007
Copy link to clipboard
Copied
A better approach might be to figure out a way to get your data without running 27 queries.
Votes
0
Upvote
Translate
Translate
Report
Report
Follow
Report
More
Reply
Reply
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Stressed_Simon
Engaged
,
/t5/coldfusion-discussions/looping-and-setting-cfset-values-from-a-query/m-p/323122#M29205
Aug 25, 2007
Aug 25, 2007
Copy link to clipboard
Copied
In the main everything is in CF is in a struct. Armed with this information you use array notation to help you.
<cfloop index="iCount" from="1" to="27">
<cfset variables["ans" & iCount] = (variables["qryGetPcts" & iCount]["q" & iCount & "Ct"] / qryGetCounts.qID2) * 100>
</cfloop>
Votes
0
Upvote
Translate
Translate
Report
Report
Follow
Report
More
Reply
Reply
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Stressed_Simon
Engaged
,
/t5/coldfusion-discussions/looping-and-setting-cfset-values-from-a-query/m-p/323123#M29206
Aug 25, 2007
Aug 25, 2007
Copy link to clipboard
Copied
In Response To Stressed_Simon
But as
Dan Bracuk
rightly points out, you can probably generate this in the db much cleaner and more efficiently when you get the original query.
Votes
0
Upvote
Translate
Translate
Report
Report
Follow
Report
More
Reply
Reply
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
cf_dev2
Guide
,
/t5/coldfusion-discussions/looping-and-setting-cfset-values-from-a-query/m-p/323124#M29207
Aug 25, 2007
Aug 25, 2007
Copy link to clipboard
Copied
Not to keep harping on this point, but as mentioned here and in another thread, using a more normalized structure would simplify your code and queries. This design makes things more complicated than they need to be.
Votes
0
Upvote
Translate
Translate
Report
Report
Follow
Report
More
Reply
Reply
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Guest
AUTHOR
/t5/coldfusion-discussions/looping-and-setting-cfset-values-from-a-query/m-p/323125#M29208
Aug 25, 2007
Aug 25, 2007
Copy link to clipboard
Copied
LATEST
Thanks Simon/cf_dev2, I hadn't really looked into this much and threw it together. I'll take a second look.
Votes
0
Upvote
Translate
Translate
Report
Report
Follow
Report
More
Reply
Reply
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Post Reply
Preview
Exit Preview
never-displayed
You must be signed in to add attachments
never-displayed
Â
Resources
Documentation
ColdFusion User Guide