2

I have a struct that contains 2 queries. I have a variable with the "key" of one of the queries, and I want to output the query dynamically using that variable. My basic code:

<cfquery name="myQueries.names" ... >...</cfquery>
<cfquery name="myQueries.places" ... >...</cfquery>

<cfset queryName = "places" />

<cfoutput query="myQueries[queryName]">
...
</cfoutput>

This gives me the error Attribute validation error for tag cfoutput.

The cfoutput "query" attribute doesn't seem to support bracket notation. How can I access the query from the cfoutput?

froadie
  • 79,995
  • 75
  • 166
  • 235

1 Answers1

7

The query attribute of cfoutput requires a valid variable name, so you can set an intermediary value and use that to reference your query

<cfset realQuery = myQueries[queryName]>
<cfoutput query="realQuery">
...
</cfoutput>
Matt Busche
  • 14,216
  • 5
  • 36
  • 61