ColdFusion question: variable within variable in CFOUTPUT

My Googling skills suck, and I’m new to CF. I would’ve posted this elsewhere, but my news server won’t subscribe to macromedia.* newsgroups :(, and using Google Groups takes fooooorever–I’d like to know by the end of today.

But, how would I refer to a variable within a variable? e.g…

<cffunction name=“myFunction”>
<cffargument name=“myField”>

<cfquery name=“myQuery”> select #myField# from aTable </cfquery>
<cfoutput query=“myQuery”>

<! – this is the part I’m having trouble with, how do I refer to the SQL values within #myField# … e.g., a variable within a variable like #(#myField#)# -->

</cfoutput>
</cffunction>

Thanks so much!

i’m not quite sure what you mean - could you explain it a bit more?

Look at the example. I am passing it the name of a field in a SQL database, and I want it to print out the contents of the field.

Let’s say the database table myTable has one field (column), employeeName. There are three entries/rows in employeeName… Mary, James, Rick.

I call:
<CFOUTPUT>
#myFunction( “employeeName” )#
</CFOUTPUT>

The actual output, using #myField# between the cfoutput tags in the cffunction:
employeeName employeeName employeeName

What I want:
Mary James Rick

Look at the example more closely and you’ll understand what I want…

Blimey! Easy tiger! No need to bite me head off! I just wanted to make sure i could answer your question properly.

Well if i’m figuring you right what you want is this:

<cfset myField = “wooYay” />

<cfquery datasource=“myDatasource” name=“getField”>

select #myField# from myTable

</cfquery>
<cfoutput query=“getField”>

#evaluate(“getField.#myField#”)#

</cfoutput>

That right?

It works! Thanks so much!

I didn’t mean to come across as biting your head off… I wasn’t being negative/snippy/anything… :frowning: Just trying to clarify the best I could, but I couldn’t think of a better example than the function I wrote in the OP… :frowning: It is somewhat difficult to explain, and difficult to Google as a result.

In any case, thank you SOOOOO much! :slight_smile: :smiley:

no probs mate - sorry for any misunderstanding.

for the record whilst you can use evaluate for other “variable within a variable” scenarios (form, url, session etc.) in Coldfusion MX and above, it is generally recommended that whenever possible you work within scopes as its quicker/cleaner. So, for example, if you were doing the same thing as above but with a form you’d use:

#form["#myField#"]#

rather than:

#evaluate(“form.#myField#”)#

anyway,

any other problems/questions either post them here or feel free to drop me a mail.

Of course–thanks! It was a quick slap-something-together project for the boss. Hopefully I won’t have to touch it again. :slight_smile: Thanks soooo much! :slight_smile: