Skip to main content
January 2, 2009
Answered

Looping over Nested Structure

  • January 2, 2009
  • 3 replies
  • 777 views
Hey Guys,
I have a component that returns a structure. The structure is called ContactQuery. ContactQuery has to elements, one called Results, and one called Success. Results contains the data I want to loop over. If you try looping over the ContactQuery by using CFLoop and specify the ContactQuery as the collection, of course it only loops twice (once for Results, once for Success). How can I loop over the Results structure withing ContactQuery? You can see the dump of the structure at:
http://www.digitalswordsmen.com/cfschedule/admin/Create_Tokens_Table.cfm

Attached is the code I have. I am just unsure of the syntax for looping over the Results section of the structure.

Thank you.
This topic has been closed for replies.
Correct answer -__cfSearching__-
It looks like it is query. Did you try a regular query loop?

<cfloop query="ContactQuery.Results">
...
</cfloop>

3 replies

-__cfSearching__-Correct answer
Inspiring
January 2, 2009
It looks like it is query. Did you try a regular query loop?

<cfloop query="ContactQuery.Results">
...
</cfloop>
January 2, 2009
Nope. I am dumb and didn't really think about it. The fact that it is a query nested in a structure threw me off. The code that works was

<cfloop query="ContactQuery.Results">


<tr>
<td></td><td>#firstname#</td><td>#lastname#</td><td>#email#</td><td>#randrange(10000,99999)#</td>
</tr>

</cfloop>

Thanks for the help, sorry about that dumb question.
Inspiring
January 2, 2009
Can you dump the Results object? The test page just shows an error "Variable USERNAME is undefined"
January 2, 2009
Oh Sorry about that.
I set the username and pass in an application.cfm in another dir. Copied it over to that dirs application.cfm. You should be able to run it now.
Inspiring
January 2, 2009
Try using ContactQuery.Results instead of ContactQuery. Though it is not clear whether "Results" is a structure or a query object.
January 2, 2009
Thanks for the quick reply.
Using
<cfloop collection="#ContactQuery.Results#" item="i">
Yields and error. I did try that first, since it made sense to me that it should work. However it does not. Not real sure why. Maybe you are onto something when you mentioned you were unsure if it was a structure or a query object.