How to exit Cfoutput

I am viewing the query results and I need to limit the number of rows displayed. I need to use cfoutput because I use the group attribute and I cannot use maxrows because not all lines will be displayed.

I tried using <cfbreak> inside <cfoutput> , but this is causing an error.

How can I break out of the <cfoutput> ?

+8
coldfusion cfoutput
source share
2 answers

If your group exists only to remove duplicates from the results, I would suggest using your query to shorten them, then you can cfloop (select the selection and reduce the list of returned columns).

If you use your group to β€œgroup” your results, you can run the counter in your loop and the cfif statement in your first loop to omit later results.

You can fake a group by parameter in your cfloop by matching the value from the previous line if you need cfbreak

 <cfloop query="queryname"> <cfif queryname.column[currentrow-1] neq queryname.column[currentrow]> #queryname.column# </cfif> </cfloop> 

Random note: you can click on any / all levels of grouped cfoutput

 <cfset tmp = querynew('id,dd')> <cfloop from="1" to="20" index="i"> <cfset queryaddrow(tmp,1)> <cfset querysetcell(tmp,'id',rand(),i)> <cfset querysetcell(tmp,'dd',(i mod 4),i)> </cfloop> <cfquery dbtype="query" name="tmp">select * from tmp order by dd</cfquery> <cfoutput query="tmp" group="dd" maxrows="2">#dd#<br <ul> <cfoutput maxrows="2" group="id"><li>#id#</li></cfoutput> </ul> </cfoutput> 
+8
source share

You can use the cfthrow tag to raise an exception that allows you to exit the loop with cfcatch, after which you can ignore the exception and continue processing. This will give you what you want.

  <cftry> <cfset i = 0> <cfoutput query="qMyQuery" group="someGroup"> <cfset i = i + 1> Parent <cfoutput> Child </cfoutput> <cfif i GTE 10> <cfthrow type="break"> </cfif> </cfoutput> <cfcatch type="break"> <!--- DO NOTHING - THIS IS A HACK FOR NOT BEING ABLE TO USE CFBREAK inside cfoutput. ---> </cfcatch> </cftry> 
+4
source share

All Articles