ColdFusion-将行显示为列 [英] ColdFusion - Displaying rows as columns

查看:79
本文介绍了ColdFusion-将行显示为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ColdFusion构建一个计分卡,该计分卡将允许更新数据。我需要将行显示为列,将行显示为列。这是表格的示例:

I'm building a scorecard with ColdFusion which will allow for updating data. I need to display the data with the rows as columns and columns as rows. Here is an example of the table:

Mon Met1 Met2 Met3 Met2 Met5
Jan 15    24   21   40   50
Feb 30    21   14   39   44
Mar 15    19   20   28   19
Apr 16    31   33   21   43

我想像这样显示数据(翻转行和列):

I want to display the data (flipping the rows and columns) like this:

Metric Jan  Feb   Mar  Apr

Met1   15   30   15   16  
Met2   24   21   19   31 
Met3   21   14   20   33
Met4   40   39   28   21
Met5   50   44   19   43

任何帮助将不胜感激。
谢谢

Any help would be appreciated. Thanks

推荐答案

听起来像我几年前写的垂直排序常见问题解答。也许这会有所帮助:

Sounds like a 'vertical sorting' FAQ I wrote years ago. Perhaps this will help:

<html>
<head>
   <title>Vertical Sorting</title>
</head>
<cfquery name = "qMyQuery" datasource = "dsn">
   SELECT fields
   FROM   table
   ORDER BY myField
</cfquery>
<body>
<!--- set the number of colums you wish to have --->
<cfset cols = 5>
<!--- get the number of rows so you know what record to display at the top of the next row. for example if our query contains "a,b,c,d,e,f,g,h,i,j,k,l,m" (13 elements) it will produce 3 totalrows--->
<cfset totalRows = ceiling(qMyQuery.RecordCount / cols)>
<!--- set inital record to 1 "output" is the actual cell of the query --->
<cfset output = 1>
<!--- Create table --->
<table width = "100%" border="0" align="center" cellpadding="2" cellspacing = "2">            
    <!--- loop through the rows.  This loop will run 3 times in this example --->
    <cfloop from = "1" to = "#totalRows#" index = "thisRow">
    <tr>
        <!--- this loop will run 5 times in times in this example --->
        <cfloop from = "1" to = "#cols#" index = "thisCol">
        <!--- the width in the table cell will dynamicaly calculated to evenly distribute the cells. in this example if cols = 5 100/5 will make the cells 20% of the table --->
        <td width = "<cfoutput>#numberformat((100/cols), 99)#</cfoutput>%" align="center" nowrap style = "border: 1px solid #ccc;">
            <!--- Check current record with the record count, this will be used to display data or an empty cell --->
            <cfif output lte qMyQuery.recordCount>
                <cfoutput>#qMyQuery.Mon[output]#</cfoutput>
            <cfelse>
            <!--- use <br> to display an empty cell --->
                <br>
            </cfif>
            <!--- increment counter to the next record in this example if we started on the first cell of the first row it would be 1(a), then 4(d), then 7(g) and so on if this was the firs cell on the second row it would be 2(b), 5(e), 8(h), continue... --->
            <cfset output = output + totalRows>
        </td>
        </cfloop>
        <!--- this little bit tells where to start the next row. if we just finished the first row output would be 2(b) --->
        <cfset output = thisRow + 1>
    </tr>
    </cfloop>
</table>
</body>
</html>

这篇关于ColdFusion-将行显示为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆