Copy link to clipboard
Copied
<!---page1.cfm--->
query returned 3 IDs (1,2 and 3). Loops over each ID and call page2 then pass each ID over.
<cfloop query="my_qr">
<cf_page2 id= "#id#" />
</cfloop>
<!---page2.cfm--->
<cfoutput>
ID:#attributes.id#
</cfoutput>
tested it and only frst ID (1) is passed over to page2 instead of 1, 2 and 3?
thanks
Copy link to clipboard
Copied
Is the first attribute being passed once or thrice? What happens if you do this?
<cfloop query="my_qr">
<cfdump var="before #id#> <br>
<cf_page2 id= "#id#" />
<cfdump var="after #id#><br>
</cfloop>
<!---page2.cfm--->
<cfoutput>
ID:#attributes.id#
</cfoutput>
Copy link to clipboard
Copied
Only one for the first attribute. Yes, I did dump the id before and after and I see all three id(1,2,3). Any suggestions?
i just found out that this code is worked as expected on coldusion 8 but not 7. CF 7 is only pass the first attribute over, is there any sugesstion to make it work in cf 7?
Thx
Copy link to clipboard
Copied
Firstly, you should always scope your query variables. This helps make the code more readable (so you always know where a value is coming from), and more importantly, prevents the chances of for instance 'id' having been defined in a different scope, which your code is then using instead of the 'id' from the query you expect it to use.
<cfloop query="my_qr">
<cf_page2 id= "#my_qr.id#" />
</cfloop>
Secondly, you have a closing /> on your custom tag call to page2.cfm. This is the equivalent of doing <cf_page2></cf_page2>. Which means page2.cfm gets executed twice, once for the opening tag and once for the closing tag. Normally you'd check the thisTag.executionMode to see which part it's being called from. See http://www.petefreitag.com/item/64.cfm - you probably just want to remove the trailing / from <cf_page2 id= "#my_qr.id#" /> , so it only gets executed once (and you don't have to then rewrite page2.cfm).
Copy link to clipboard
Copied
try your and and attribute being passed twice now, meaning i got same ID 1 twice. any sugestion?
Copy link to clipboard
Copied
If you got the same id twice, try changing to this
id= "#my_qr.id#"
to this
id= "#my_qr.id[current_row]#"
If you don't specify the row, ColdFusion uses the first one. That's not normally necessary in a query loop, but it might be in this case because you qualified the variable.
Copy link to clipboard
Copied
I am with Duncancumming. It is as simple as
<cfloop query="my_qr">
<cf_page2 id="#id#">
</cfloop>
Copy link to clipboard
Copied
<!---page1.cfm--->
query returned 3 IDs (1,2 and 3). Loops over each ID and call page2 then pass each ID over.
<cfloop query="my_qr">
<cf_page2 id= "#id#" />
</cfloop>
<!---page2.cfm--->
<cfoutput>
ID:#attributes.id#
</cfoutput>
tested it and only frst ID (1) is passed over to page2 instead of 1, 2 and 3?
Is it a case of onlythe first ID is being passed (so you get "1","1","1"), or that the loop is not iterating three times (eg: you're getting just "1")?
Irrespective of whether you scope your query, the col in the query should be the first one one found when CF goes to find what you mean by "id", so even if you had URL.id, form.id and variables.id set elsewhere, if my_qr has an "id" column, that'd be the one used. This code demonstrates:
<!--- test.cfm --->
<cfscript>
URL.id = 4;
form.id = 5;
variables.id = 6;
q = queryNew("");
queryAddColumn(q, "id", [1,2,3]);
queryAddColumn(q, "data", ["one", "two", "three"]);
</cfscript>
<cfloop query="q">
<cf_tag id="#id#">
</cfloop>
<!--- tag.cfm --->
<cfparam name="attributes.id" default="0">
<cfoutput>
ID:#attributes.id#<br />
</cfoutput>
This outputs:
ID:1
ID:2
ID:3
Which is what one should expect.
I ran this test on CF9.0.1, but woudl expect CFMX7.x to be the same. I will verify this when I get home in a coupla hours time (I don't have CFMX7.x to hand here).
--
Adam