CFU*_*ser 2 coldfusion cfquery
如何在不使用ColdFusion中的Results.columnname的情况下打印所有结果
对于前: -
我有 <cfquery name="getProductId">
select productId
from product
</cfquery>
在Product Table中,我有2列product_name和Product_id.
如何在不使用getProductId.product_name getProductId.Product_id的情况下打印它们
谢谢,
你想要实现什么目标?如果您正在寻找一种基于您不知道的列名称的查询计算输出查询结果的方法,例如...
<cfquery name="queryName" ...>
select * from product
</cfquery>
Run Code Online (Sandbox Code Playgroud)
...然后您可以使用该queryName.ColumnList变量,该变量返回所有列名称的逗号分隔列表.您可以随后迭代此列表,并根据需要输出.
例如,要获得简单的HTML表输出:
<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>
Run Code Online (Sandbox Code Playgroud)
如果这不是你的意思,请道歉!