Coldfusion 使用group时如何查找嵌套的cfoutput recordcount
考虑以下几点:Coldfusion 使用group时如何查找嵌套的cfoutput recordcount,coldfusion,coldfusion-10,cfloop,cfoutput,Coldfusion,Coldfusion 10,Cfloop,Cfoutput,考虑以下几点: <cfoutput query="resources" group="type"> <h4>#type#</h4> <cfoutput> #name# </cfoutput> </cfoutput> 我可能会对循环进行一些黑客操作,但我想知道是否有专门使用cfoutput组的方法。恐怕您必须自己进行一些计数。没有针对的记录计数 嵌套的分组输出,因为它
<cfoutput query="resources" group="type">
<h4>#type#</h4>
<cfoutput>
#name#
</cfoutput>
</cfoutput>
我可能会对循环进行一些黑客操作,但我想知道是否有专门使用cfoutput组的方法。恐怕您必须自己进行一些计数。没有针对的记录计数 嵌套的分组输出,因为它实际上是所有相同的查询,CF只是
正在为您执行一些格式化操作。要获取嵌套数据的计数并将其显示在您希望的位置,我将执行以下操作:
<cfoutput query = "rescources" group = "type">
query of queries to get the count this type
output the type and the count
<cfoutput>
output nested data
</cfoutput>
</cfoutput>
查询以获取此类型的计数
输出类型和计数
输出嵌套数据
如果需要其他方法,您可以在原始查询中获得计数,但是,在执行此操作之前,您需要测试性能(尽管使用查询查询也可能会有性能问题,因为没有索引)
然后在CF中,您可以执行以下操作:
<cfoutput query="resources" group="type">
<h4>#resources.type# (#resources.typeCount# of #resources.recordCount#)</h4>
<cfoutput>
#resources.name#
</cfoutput>
</cfoutput>
#resources.type#(#resources.typeCount#of#resources.recordCount#)
#资源名称#
作为旁注,在CF10中,您还可以使用如下查询在cfloop中分组:
<cfloop query="resources" group="type">
<h4>#resources.type# (#resources.typeCount# of #resources.recordCount#)</h4>
<cfloop>
#resources.name#
</cfloop>
</cfloop>
#resources.type#(#resources.typeCount#of#resources.recordCount#)
#资源名称#
您可以在获取计数之前进行输出。这将比查询查询更有效
<cfoutput query="resources" group="type">
<cfset noofrecords= 0>
<cfoutput>
<cfset noofrecords++>
</cfoutput>
<h4>#type# (#noofrecords# of #resources.recordcount#)</h4>
<cfoutput>
#name#
</cfoutput>
</cfoutput>
#键入#(#noofrecords#of#resources.recordcount#)
#名字#
另一种解决方案是:
<!--- I chose the pipe delimiter | names of things often contain commas,
otherwise, use any delimiter you like --->
<cfset TypesList = Valuelist(resources.type,"|")>
<cfoutput query="resources">
<h4>#Type# (#ListValueCount(TypesList,Type,"|")# of #resources.recordcount#)</h4>
<cfoutput>#name#</cfoutput>
</cfoutput>
基于类型(作为字符串),输出将显示红色的(4)、黄色的(1)、绿色的(1)、红色的(4),但在category products关系表结构中,基于类别的唯一ID的coutning将检索准确的计数。遗憾的是,这似乎是正确的答案!然后回到循环+QoQ。我也是这么想的,直到cfqueryparam出现。@Neokoenig-这并不意味着你需要QoQ。计数器和嵌套循环将执行相同的操作。不像query.recordCount那么优雅,但是它在没有一堆QoQ的不必要的o/h的情况下完成了工作。谢谢你的想法-我正在尝试看看是否有一种没有QoQ的方法,等等,显然没有。@Neokoenig看看我的答案。不需要QoQ。抱歉,但是循环中的QoQ为-1。这不是计算计数的最便宜的方法。谢谢你的想法-我使用的ORM意味着我必须闯入cfquery-这是我真正想要避免的。呵呵:)-好吧,那真的很狡猾。这是我以前从未见过的方法-谢谢@Neokoenig嘿,没问题,我确实意识到我忘了为ListValueCount()包含|分隔符。修正了。不管怎样,我很乐意帮忙。
<cfoutput query="resources" group="type">
<cfset noofrecords= 0>
<cfoutput>
<cfset noofrecords++>
</cfoutput>
<h4>#type# (#noofrecords# of #resources.recordcount#)</h4>
<cfoutput>
#name#
</cfoutput>
</cfoutput>
<!--- I chose the pipe delimiter | names of things often contain commas,
otherwise, use any delimiter you like --->
<cfset TypesList = Valuelist(resources.type,"|")>
<cfoutput query="resources">
<h4>#Type# (#ListValueCount(TypesList,Type,"|")# of #resources.recordcount#)</h4>
<cfoutput>#name#</cfoutput>
</cfoutput>
Fruits
Red Ones
Strawberries
Raspberries
Yellow Ones
Bananas
Vegetables
Green ones
Green peppers
Red Ones
Red Peppers
Tomatoes