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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advanced Variables 1

Status
Not open for further replies.

ice7899

Programmer
May 14, 2006
59
GB
Is it possible to use a variable in a <cfoutput query => expression

For example

<cfset myVar="colID">

<cfoutput query = "someQuery"....>

Value in first column is #someQuery[myVar]#

</cfoutput>

Tha above does not work. Also tried someQuery[variables.colID]

That doesn't work either !

So is it possible?
 
try:

<cfoutput query = "someQuery"....>

Value in first column is #myVar#

</cfoutput>
 
How are you populating the myVar variable? When you call the myVar variable is the value going to be different?

Can you give a real-world example on how you intend to use this?

____________________________________
Just Imagine.
 
From your example myVar would have a value of "colID"

try this:
<code>
<cfquery name="someQuery" datasource="mySource">
select field1,field2
from myTable
</cfquery>

<cfoutput query = "someQuery"....>
Value in first column is #someQuery.field1#,
Value in first column is #someQuery.field2#<br>
</cfoutput>
</code>
 
I was asked for a real world example. Well what I was trying to do is this. I wanted to build a custom tag that I would take a query passed in as an attribute and display it in a table. It all worked well ( i could get a recordcount of the query in my tag) but when it got to trying to output the tag, it flagged an error saying that I was using a complex type where I should be using a simple type. I've been trying various ways of getting this query to output but couldn't get it to work. So I tried a working it as a <cfinclude> instead passing variables into it. But trying to pass a variable that is used by <cfoutput query = > does not seem workable.
So in the above example

<cfset myVar="colID">

<cfoutput query = "someQuery"....>

Value in first column is #someQuery[myVar]#

</cfoutput>

colID is a variable that I define in a .cfm file which is then used by the included file which is meant to run the query.




 
Are you trying to pass the query column name as a variable?

If so:

<cfset myVar='somequery.'&colID>

<cfoutput query = "someQuery"....>

Value in first column is #Evaluate(myVar)#

</cfoutput>


 
Are you trying to pass the query column name as a variable?

If so:

<cfset myVar='somequery.'&colID>

<cfoutput query = "someQuery"....>

Value in first column is #Evaluate(myVar)#

</cfoutput>


...This is exactly what I was after. My only concern is that I have read that Evaluate() is not very good in terms of performance. Maybe this will make no difference if it is used for a simple display table? Is this my only option ?

I've been playing with someQuery[variables.colID] etc but does not work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top