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

Reference a query in a custom tag

Status
Not open for further replies.

peterswan

Programmer
Sep 25, 2002
263
0
0
US
I think the sytax to pass a query to a custom tag is like this:

<cfquery name="getContracts" datasource="dsn">
Select
whatever
</cfquery>

<cf_contracts query="getContracts">

However, how do you then access this recordset in the custom tag?

I tried:

<cfoutput query="#attributes.query#> and
<cfouput query="getContracts">

but both of these drew an error, saying the query was not available.

Thanks,

Peter
 
you have to use the attributes prefix along with the column name. here is a good pdf for you to read. page 7 covers passing structures

attributes.query.colName

I'd avoid naming a variable "query"

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Hi TruthInSatire,

It sounds like attributes.query.colName will reference the column once, but what if I want to loop through an entire query recordset?

I can't see a link or a URL to the PDF file you mentioned. Could you please send again.

Thanks for your help.

Peter [smile]
 
sorry,

this works for me though.

caller:
Code:
<cfquery datasource = "dsIMmadeUp" name = "users">
	Select * from usersTable
</cfquery>
<cf_output myQuery = "#users#">

tag (output.cfm)
Code:
<cfoutput query = "attributes.myQuery">
#attributes.myQuery.firstName# #attributes.myQuery.lastName#<br>
</cfoutput>

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Hmm.
I did

from caller:
<cf_mytag thequery="thisquery">

from the tag:
<cfoutput query="caller.#attributes.thequery#">
#item_id#, #item_name#, #item_price# etc..
</cfoutput>

 
you're missing it...

<cf_mytag thequery="#thisquery#">

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
So my way leaves the query in the caller scope and calls it as call.#thisquery# in the tag.

Yours moves the query into the attributes scope for the tag be evaluating it into an attribute variables value.

Is that the only real difference? because I've been doing it like I posted for a while now.

 
I can't remember where i read it, but the caller scope has had problems in the past. weather the problems have been fixed or not, i'm not sure.

I'm sorry I can't cite my source, I wish I could remember what it was.

So I just avoid using the caller scope to avoid problems. what works for you is good for you, hope you don't run into any problems.

Yours moves the query into the attributes scope

no, it copies the structure. Copies of structures act as pointers to the original.

the way to COPY a structure is by using the structCopy() function

livedocs structCopy page goes into copying values vs reference


We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top