Evaluating a variable which is part of an evaluated variable

I have this query statement:

<cfquery datasource=“artworks” name=“qColors”>
SELECT *
FROM colors
</cfquery>

Then in my output section:

<cfoutput query=“qColors”>
#qColors.blue#
</cfoutput>

This is all fine and good. But what I really want is for “blue” to be a variable, in essence, like this:

<cfoutput query=“qColors”>
#qColors.(#myVar#)#
</cfoutput>

Where “myVar” is part of the VARIABLES scope. Is it possible to evaluate “myVar” first, then have its result used in the evaluation of the query variable?

I hope this makes sense. Thank you in advance for any help with this.

-Anthony

#Evaluate(“qColors.” + myVar)#

Can I ask - the select * - what is that pulling back? Is it a column for every colour?

What are you hoping to achieve here? In terms of your variable setup and cfoutput display.

Cheers
James

r937,

Your syntax worked, although I had to use an “&” instead of the “+” sign, like so:

#Evaluate(“qColors.” & myVar)#

Thank you very much!!

-Anthony

ah, sorry, well spotted :blush:

Depended on how bothered you are but Evaluate is a bottleneck on performance and in the vast majority of times can be done another way, hence why I was asking the column structure returned by your query :slight_smile:

Can you not use - qColors[myVar] or if square brackets disagree with querying then try ().

Cheers
James

bottleneck??

Clarkee21,

I tried the square brackets and the parentheses, but I got errors with both.

This did not work for me:

<cfoutput query=“qColors”>
#qColors[myVar]#
</cfoutput>

Thanks,
Anthony

bottleneck??

Yeap - Do a Google on ColdFusion Evaluate and read the raving reviews it gets :slight_smile:

No worries Ant - I’m just saying it’s something to be aware of when using that function. In most cases you can find a better / quicker approach, but I can’t make any decent suggestions until I know the structure of your database “color” table