我想从查询中输出结果,结果如下,query = gettotalstars

我使用<cfoutput query="GetTotalStars" group="month">
但是这会为所有人重复输出.有没有其他方法可以做到这一点不使用"组"或更好的方法来做到这一点?
最后,我希望它能像这样显示输出:(很明显,从我现在设置表的方式来看,它不会像我想要的那样给我结果)

这是我现在正在使用的代码:
<cfoutput query="GetTotalStars" group="month">
<table cellpadding="0" cellspacing="0" class="tablesorter">
<thead><th></th><th>January</th><th>Frebruary</th>......</thead>
<tbody>
<cfloop query="GetTotalStars" >
<tr>
<td>#csedept_name#</td>
<td><div align="right">#TOTALSTARS#</div></td>
</tr>
</cfloop>
</tbody>
</cfoutput>
</table>
Run Code Online (Sandbox Code Playgroud)
在之前的回复中有很多争议.我将尝试根据您展示的内容提供最简单的解决方案.如果您有多年或者如果您在任何给定月份都有空数据,那么您需要为自己解决许多问题.在试图引导你理解而不实际完成所有工作的同时,我实际上已经为你提供了一套完整的解决方案.您需要调整并退回其中一些以处理数据中的漏洞或其他可能的边缘情况.总而言之,它应该引导您采用可以构建的方法来处理这些其他可能性.它确实使用查询查询来梳理标题行.我认为这是导致更复杂的解决方案的部分.
<cfscript>
GetTotalStars = querynew(
"dept_id,csedept_name,totalstars,year,month",
"integer, varChar, integer, integer, integer",
[
{
dept_id:1
,csedept_name:'department 1'
,totalstars:5
,year:2014
,month:5
}
,{
dept_id:1
,csedept_name:'department 1'
,totalstars:4
,year:2014
,month:6
}
,{
dept_id:2
,csedept_name:'department 2'
,totalstars:3
,year:2014
,month:5
}
,{
dept_id:2
,csedept_name:'department 2'
,totalstars:6
,year:2014
,month:6
}
]
);
writedump(GetTotalStars);
</cfscript>
<!---
I agree with previous arguments about exessive use of query of queries.
But for your header row (and to get a full list of possible months), you
really need to pull that out of the original query in a single list or array or struct
--->
<cfquery dbtype="query" name="qryMonths">
select distinct [month] from GetTotalStars order by [month]
</cfquery>
<cfoutput>
<table border="1">
<thead>
<tr>
<th>Department</th>
<!---
If you have gaps in the data, it might make sense to build an
array here to keep track of what month is in what column
--->
<cfloop query="qryMonths">
<th>#MonthAsString(qryMonths.month)#</th>
</cfloop>
</tr>
</thead>
<tbody>
<!---
This is just a straightforward nested query and group loop.
If you have nulls in the data, you would check against the array
that you built in the top section to figure out which column you
are in
--->
<cfloop query="GetTotalStars" group="csedept_name">
<tr>
<td>#GetTotalStars.csedept_name#</td>
<cfloop group="month">
<td>#GetTotalStars.totalstars#</td>
</cfloop>
</tr>
</cfloop>
</tbody>
</table>
</cfoutput>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
421 次 |
| 最近记录: |