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

nested CFOUTPUT

Status
Not open for further replies.

bierltrinka

Programmer
Nov 23, 2002
3
GB
Hello!

How can I nest CFOUTPUTs? The CFOUTPUTs are not related to each other so I can't group them.
the "outer" CFOUTPUT deplays the records from the database to change by the user and the "inner" CFOUTPUT fills a "select-list".

e.g.

<CFOUTPUT QUERY=&quot;UpdateDealer&quot;>

<INPUT TYPE=&quot;text&quot; NAME=&quot;Fi_speed&quot; VALUE=&quot;#Fi_speed#&quot;>
<select size=&quot;1&quot; name=&quot;Ma_ID&quot;>

<CFOUTPUT QUERY=&quot;MakeList&quot;>
<option value=&quot;#Ma_ID#&quot;>#Ma_Make#</option>
</cfoutput>

</select>

</CFOUTPUT>


This is the errortext:
&quot;A query driven CFOUTPUT tag is nested inside a CFOUTPUT tag that also has a QUERY= attribute. This is not allowed. Nesting these tags implies that you want to use grouped processing. However, only the top-level tag can specify the query that drives the processing. &quot;

Thanks in advance!
 
if you have only one CFQUERY, your problem will be resolved by using the GROUP= parameter on the outer CFOUTPUT, and removing the QUERY= parameter from the inner CFOUTPUT

if you actaully have two queries, you can't nest the CFOUTPUTs like that

please

1. in your code, scope your variables

2. show the two queries (and maybe a few lines of sample data from each)


rudy
 
Hi!

the problem is: I cannot group them because these are query from different tables:


<CFQUERY
NAME=&quot;UpdateDealer&quot;
DATASOURCE= &quot;oratest&quot;
username=&quot;xxx&quot;
password=&quot;xxx&quot;>

SELECT
Fi_ID,
Ma_ID,
Fi_speed,
Fi_numbofphotos
FROM Fi_Filmtype
WHERE Fi_ID = '#url.TypeID#'

</CFQUERY>

<cfquery
name=&quot;MakeList&quot;
datasource=&quot;oratest&quot;
username=&quot;xxx&quot;
password=&quot;xxx&quot;>

SELECT Ma_ID,
Ma_Make
FROM Make
order by Ma_ID
</cfquery>

the &quot;makelist&quot;-query I use to fill the select-box.
Is there any other way to do this (instead this):

<select size=&quot;1&quot; name=&quot;Ma_ID&quot;>
<CFOUTPUT QUERY=&quot;MakeList&quot;>
<option value=&quot;#Ma_ID#&quot;>#Ma_Make#</option>
</cfoutput>
</select>

The select-list is the only reason why I need to nest the CFOutPUT.



How can I scope my variables? (I'm no CF programmer :))

Thanks very much!

Günther
 
scoping your variables means you write #queryname.foo# instead of #foo#, #form.bar# instead of #bar#, etc.

you did scope #url.TypeID#

the only time it is acceptable to leave the scope off is
1. when it's a local variable (i.e. it's okay to write #qux# instead of #variables.qux#), and
2. if you are taking advantage of the default evaluation sequence(*), which will surely confuse anybody who has to maintain your code

(*) anybody got a url for this? i can't find it on the macromedia site anymore -- i think it was: variables, then form, then url, then session... but i could be wrong

anyhow günther, i'm not sure how your two queries relate

it looks like UpdateDealer returns only one row, which you are using to create the INPUT tag

if it returns only one row, just close its CFOUTPUT before starting the one for the makes

otherwise, if there is more than one row from UpdateDealer, and you want the complete list to be repeated under its INPUT tag, then a nested CFLOOP is required for the makes


rudy
 
thank you very much!
Updatedealer returns only one row, so I can close the CFOUTPUT before starting the one for the makes!

Cheers,
Günther
 
There's several ways you can do this.

If your first query only returns one record, don't specify query=&quot;UpdateDealer&quot; in your first cfoutput tag. Then you will need to scope your variables (as a previous user suggested). To do this, use #UpdateDealer.Fi_speed# instead of just #Fi_speed#. Do this for each variable returned by the query. Finally, use CFLOOP instead of cfoutput for your MakeList query. That's it! Below is your code example updated to reflect these suggestions.

<CFOUTPUT>

<INPUT TYPE=&quot;text&quot; NAME=&quot;Fi_speed&quot; VALUE=&quot;#UpdateDealer.Fi_speed#&quot;>
<select size=&quot;1&quot; name=&quot;Ma_ID&quot;>

<CFLOOP QUERY=&quot;MakeList&quot;>
<option value=&quot;#MakeList.Ma_ID#&quot;>#MakeList.Ma_Make#</option>
</cfloop>

</select>

</CFOUTPUT>


The second way is to wrap the entire code in one cfoutput tag. Then just use CFLOOP instead of CFOUTPUT. This works because you can nest CFLOOP tags. For example:

<CFOUTPUT>
<cfloop query=&quot;UpdateDealer&quot;>

<INPUT TYPE=&quot;text&quot; NAME=&quot;Fi_speed&quot; VALUE=&quot;#UpdateDealer.Fi_speed#&quot;>
<select size=&quot;1&quot; name=&quot;Ma_ID&quot;>

<CFLOOP QUERY=&quot;MakeList&quot;>
<option value=&quot;#MakeList.Ma_ID#&quot;>#MakeList.Ma_Make#</option>
</cfloop>

</select>

</cfloop>
</CFOUTPUT>


If you ever &quot;have&quot; to nest cfoutput tags, maybe if you are grouping the output, you can either put the nested cfoutput in another file and then use cfinclude to include the file. Or, write the nested cfoutput before the rest of your code, wrap it in the cfsavecontent tag (which saves the output to a simple variable), then output the variable within your code (where you would have nested the cfoutput tag). For example:

<cfsavecontent variable=&quot;selectBox&quot;>
<select size=&quot;1&quot; name=&quot;Ma_ID&quot;>
<CFLOOP QUERY=&quot;MakeList&quot;>
<option value=&quot;#MakeList.Ma_ID#&quot;>#MakeList.Ma_Make#</option>
</cfloop>
</select>
</cfsavecontent>

<CFOUTPUT query=&quot;myQuery&quot; group=&quot;dealerID&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;Fi_speed&quot; VALUE=&quot;#UpdateDealer.Fi_speed#&quot;>
<cfoutput>#selectBox#</cfoutput>
</CFOUTPUT>

HTH,

Brad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top