如何在ColdFusion中不使用Results.columnname打印所有结果 [英] How to print all the result without using Results.columnname in ColdFusion

查看:169
本文介绍了如何在ColdFusion中不使用Results.columnname打印所有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ColdFusion中不使用Results.columnname打印所有结果

How to print all the result without using Results.columnname in ColdFusion

例如: -

我有< cfquery name =getProductId>
选择productId
从产品
< / cfquery>

带有product_name和Product_id。

In Product Table i have 2 columns with product_name and Product_id.

如何在不使用
的情况下打印它们getProductId.product_name
getProductId.Product_id

How can I print them without using getProductId.product_name getProductId.Product_id

感谢,

推荐答案

你想达到什么?如果你正在寻找一种方法来计算地输出查询结果基于查询的列名你不知道,如...

What are you trying to achieve? If you are looking for a way to computationally output query results based on a query whose column names you do not know, such as...

<cfquery name="queryName" ...>
    select * from product
</cfquery>

...那么你可以使用 queryName.ColumnList 变量,它返回所有列名称的逗号分隔列表。

...then you can use the queryName.ColumnList variable, which returns a comma separated list of all column names. You could subsequently iterate over this list, and output as required.

例如,要获取一个简单的HTML表格输出:

For example, to get a simple HTML table output:

<table border=1>
    <cfloop from="0" to="#queryName.RecordCount#" index="row">
        <cfif row eq 0>
            <tr>
                <cfloop list="#queryName.ColumnList#" index="column" delimiters=",">
                    <th><cfoutput>#column#</cfoutput></th>  
                </cfloop>
            </tr>
        <cfelse>
            <tr>
                <cfloop list="#queryName.ColumnList#" index="column" delimiters=",">
                    <td><cfoutput>#queryName[column][row]#</cfoutput></td>
                </cfloop>
            </tr>
    </cfif>
    </cfloop>
</table>

如果这不是你的意思,抱歉。

Apologies if this isn't what you meant!

这篇关于如何在ColdFusion中不使用Results.columnname打印所有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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