Reputation: 47645
Is there a better way to write the following?
<cfloop list="#qry.Columnlist#" index="FieldName">
<cfset "form.#FieldName#" = Evaluate("qry.#FieldName#")>
</cfloop>
This loop is assigning every field in the query to a corresponding form field. I understand the evaluate function is shunned.
Upvotes: 6
Views: 2783
Reputation: 31071
Tangential, but if you were looping over multiple rows of a query, you could use the currentRow
variable in the query object to do the same thing as the accepted answer.
<cfset var someStruct = {} />
<cfset var colummnList = queryObj.columnList />
<cfloop query="queryObj">
<cfset someStruct[currentRow] = {} />
<cfloop list="#columnList#" index="fieldName">
<cfset someStruct[currentRow][fieldName] = queryObj[fieldName][currentRow] />
</cfloop>
</cfloop>
Upvotes: 1
Reputation: 32915
<cfloop list="#qry.Columnlist#" index="FieldName">
<cfset form[FieldName] = qry[FieldName][1]>
</cfloop>
?
Upvotes: 11
Reputation: 680
Assuming you are returning a single recordset the following will work.
<cfloop list="#qry.Columnlist#" index="FieldName">
<cfset "form.#FieldName#" = qry[FieldName][1]>
</cfloop>
Upvotes: 4