我有一个CFQuery从表格中提取数据,我希望以一种格式输出到屏幕,该格式根据“公司名称”列之一对数据进行分组。我似乎无法绕过这个逻辑。
目前,我只是循环浏览数据,将其输出到屏幕并通过水平规则标记将其分开。这不是最好的方式,它会生成一个很长的结果列表,用户需要滚动浏览。我希望通过对数据进行分组,它将更具可读性。
这是我的代码:
<!--- Feedback Query --->
<cfquery name="getFeedback" datasource="#datasource#">
select ticket_id, service_satisfaction, customer_notes, response_date, company_name
from service_verification
order by company_name
</cfquery>
<br />
<cfoutput query="getFeedback" group="company_name"><strong>Company Name: #getFeedback.company_name#</strong><br />
<cfquery dbtype="query" name="parsed">
select company_name
from getFeedback
where company_name = '#getFeedback.company_name#'
</cfquery>
(#parsed.recordcount# Responses)<br />
<cfoutput>
Ticket Number: <cfif #getFeedback.ticket_id# eq 0>No ticket associated with this feedback. This was solicited feedback.<cfelse>#getFeedback.ticket_id#</cfif><br />
Date: #DateFormat(getFeedback.response_date, 'mm/dd/yyyy')# at #TimeFormat(getFeedback.response_date, 'hh:mm:ss')#<br /><br />
Rating: <cfif #getFeedback.service_satisfaction# eq 'thumbs-up'><img src="images/thumbs-up-small.png" /><cfelse><img src="images/thumbs-down-small.png" /></cfif><br />
Customer Notes: <cfif #getFeedback.customer_notes# eq ''>No additional comments provided.<cfelse>#getFeedback.customer_notes#</cfif><br /><br />
<hr style="border-top: 1px dashed ##8c8c8c;" />
</cfoutput>
<br />
</cfoutput>
以下是来自上述查询的我的CFDUMP示例:
company_name service_satisfaction response_date ticket_id customer_notes
1 AmerTech thumbs-up {ts '2014-10-22 10:25:14'} 22667 Jeff was great. thanks
2 AmerTech thumbs-up {ts '2015-01-20 12:02:34'} 23795 Rich was good. Thanks. He needs to send out a another drive that we would like as backup to take home at night. Also, he missed one machine for backups that I need to discuss. Have someone please call . Thanks
3 AmerTech, Inc thumbs-up {ts '2015-04-16 13:56:44'} 25066
4 AmerTech, Inc thumbs-down {ts '2015-10-22 11:23:40'} 27293 Brian, I understand from Dave that you could not solve the problem and that he had to call the OEM to solve the problem. This is what I was informed. I do not know any of the details surrounding the issue. but it shouldn't take that long to install a printer on a new laptop. Why did this occur and how do I make sure it doesn't happen again. thanks mark
5 AMIB thumbs-down {ts '2014-10-02 12:18:27'} 22463 Representative did not call me upon arrival at group home as instructed and implemented changes without approval from HR
6 AMIB thumbs-up {ts '2015-06-08 09:58:03'} 25599
7 AMIB thumbs-up {ts '2016-03-10 14:10:01'} 28777
8 AMIB thumbs-up {ts '2016-03-28 09:10:37'} 29193 Michael is a great tech! Extremely helpful and responsive to our needs!
9 AMIB thumbs-up {ts '2016-03-28 10:19:19'} 28777
更新
当我将group属性添加到cfoutput标记时,它只显示组中的第一个结果
<cfloop query="getFeedback">
<cfoutput><cfoutput query="getFeedback" group="company_name">
Company Name: #getFeedback.company_name# <cfif #getFeedback.service_satisfaction# eq 'thumbs-up'><img src="images/thumbs-up-small.png" /><cfelse><img src="images/thumbs-down-small.png" /></cfif><br />
Ticket Number: <cfif #getFeedback.ticket_id# eq 0>No ticket associated with this feedback. This was solicited feedback.<cfelse>#getFeedback.ticket_id#</cfif><br />
Date: #DateFormat(getFeedback.response_date, 'mm/dd/yyyy')# at #TimeFormat(getFeedback.response_date, 'hh:mm:ss')#<br /><br />
Customer Notes: #getFeedback.customer_notes# <br /><br />
<br />
<hr></cfoutput>
</cfloop>
答案 0 :(得分:1)
摆脱循环标记。然后使用:
<cfoutput query="getFeedback" group="company_name">
<!--- OUTPUT EACH GROUP --->
Company Name: #getFeedback.company_name# <cfif #getFeedback.service_satisfaction# eq 'thumbs-up'><img src="images/thumbs-up-small.png" /><cfelse><img src="images/thumbs-down-small.png" /></cfif><br />
<cfoutput>
<!--- OUTPUT EACH RECORD --->
Ticket Number: <cfif #getFeedback.ticket_id# eq 0>No ticket associated with this feedback. This was solicited feedback.<cfelse>#getFeedback.ticket_id#</cfif><br />
Date: #DateFormat(getFeedback.response_date, 'mm/dd/yyyy')# at #TimeFormat(getFeedback.response_date, 'hh:mm:ss')#<br /><br />
Customer Notes: #getFeedback.customer_notes# <br /><br />
<br />
</cfoutput>
<hr>
</cfoutput>
这是遍历每条记录的第二个/嵌套CFOUTPUT标记。 请注意,HR在GROUP内,而不是每条记录。
如果你想获得幻想,你可以使用jQuery作为手风琴。每个GROUP都是头部,每个记录都是内容。
答案 1 :(得分:0)
这是我工作代码的最后一节。谢谢@Leigh
<!--- Feedback Query --->
<cfquery name="getFeedback" datasource="#datasource#">
select ticket_id, service_satisfaction, customer_notes, response_date, company_name
from service_verification
order by company_name
</cfquery>
<br />
<cfoutput query="getFeedback" group="company_name">
<strong>Company Name: #getFeedback.company_name#</strong><br />
<cfquery dbtype="query" name="parsed">
select company_name
from getFeedback
where company_name = '#getFeedback.company_name#'
</cfquery>
(#parsed.recordcount# Responses)<br />
<cfoutput>
Ticket Number: <cfif getFeedback.ticket_id eq 0>No ticket associated with this feedback. This was solicited feedback.<cfelse>#getFeedback.ticket_id#</cfif><br />
Date: #DateFormat(getFeedback.response_date, 'mm/dd/yyyy')# at #TimeFormat(getFeedback.response_date, 'hh:mm:ss')#<br /><br />
Rating: <cfif getFeedback.service_satisfaction eq 'thumbs-up'><img src="images/thumbs-up-small.png" /><cfelse><img src="images/thumbs-down-small.png" /></cfif><br />
Customer Notes: <cfif getFeedback.customer_notes eq ''>No additional comments provided.<cfelse>#getFeedback.customer_notes#</cfif><br /><br />
<hr style="border-top: 1px dashed ##8c8c8c;" />
</cfoutput>
<br />
</cfoutput>