Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to store cfloop index to a variable? 2

Status
Not open for further replies.

mikeali

Programmer
Nov 14, 2004
16
US
let say i have below query:

<CFQUERY NAME="GetAnswered" DATASOURCE="abc">
SELECT *
FROM NumericAnswers
WHERE AccountsId = '#SESSION.Auth.AccNum#'
AND QuestionsGroupId In (2,3,4,5,6,7,8,53,54,9,10,11)
</CFQUERY>

<CFOUTPUT query="GetAnswered">
<cfloop index="i" list="#QuestionsId#">
#i#,
</CFLOOP>
</CFOUTPUT>

The output of #i# looks like 3,4,5,6,7,9,

Is there any way to store above output into a variable so I can search through it?

Thank you in advanced.

Mike
 
if questionsID is a field in that query it's already in a variable.

<cfoutput>#GetAnswered.QuestionsId#</cfoutput>

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
but cfoutput only output the first row.

Here is what I am talking about:
NumericAnswers Table
QuestionId Row 1 = 1
QuestionId Row 2 = 6
QuestionId Row 3 = 7
QuestionId Row 4 = 8
QuestionId Row 5 = 9

<cfoutput>#GetAnswered.QuestionsId#</cfoutput>
The output will be 1

And if I use cfloop then how can I check to index of cfloop against a value?
 
Try this:
Code:
<cfset MyList = ValueList(GetAnswered.QuestionId)>
It will put all of the QuestionId values returned from the query in a comma delimited list. (1,2,3,4,5...etc...)



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
I was about to suggest valuelist like ecobb did but when you said this:
<CFOUTPUT query="GetAnswered">
<cfloop index="i" list="#QuestionsId#">
#i#,
</CFLOOP>
</CFOUTPUT>

it suggests you're trying to loop through a list that already exists in getAnswered.questionsID

if you only have one number the inner cfloop will only have one itteration.

I think what you ment to do (without using valuelist) is this
<cfset mylist = "">
<CFOUTPUT query="GetAnswered">
<cfset mylist = listappend(mylist, QuestionsId)
</CFOUTPUT>

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top