我的目標是隻輸出在「fieldList中」指定的列數據。試圖輸出查詢時獲得複雜的對象錯誤值
得到以下錯誤:
Complex object types cannot be converted to simple values. The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values. The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a cfif tag. The error occurred on line 20.
當試圖做到以下幾點:
<cfquery datasource="retailers" name="myQuery">
Select * FROM retailer
WHERE retailer_id = '#url.id#'
</cfquery>
<cfset fieldList = "company,phone,phone_secondary,fax,email,website">
<cfloop list="#fieldList#" index="i">
#myQuery[i]#
</cfloop>
不應該這項工作沒有給我一個錯誤?我覺得我只是俯瞰簡單的東西我不能在任何地方找到答案。
澄清:你是否試圖從查詢結果中輸出列名稱列表?或者你只是想做最明顯的 - 這是:循環查詢的結果(即所有的數據行)並輸出它們。我問,因爲你沒有具體說明*你想要什麼*,並且代碼(如書面)可能以任何方式。 – 2012-03-08 23:09:22