Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate function

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.

like image 832
Phillip Senn Avatar asked Jan 06 '10 19:01

Phillip Senn


People also ask

What is evaluating function example?

When we have a function in formula form, it is usually a simple matter to evaluate the function. For example, the function f(x)=5−3x2 f ( x ) = 5 − 3 x 2 can be evaluated by squaring the input value, multiplying by 3, and then subtracting the product from 5.

How do you evaluate if an equation is a function?

A function will only have one or zero outputs for any input. If there is more than one output for a particular input, the equation does not define a function. In order to be a function, each value of x should have, at most, one output value of y .


3 Answers

<cfloop list="#qry.Columnlist#" index="FieldName">
    <cfset form[FieldName] = qry[FieldName][1]>
</cfloop>

?

like image 57
Henry Avatar answered Dec 10 '22 06:12

Henry


Assuming you are returning a single recordset the following will work.

<cfloop list="#qry.Columnlist#" index="FieldName">
<cfset "form.#FieldName#" = qry[FieldName][1]>
</cfloop>
like image 42
jarofclay Avatar answered Dec 10 '22 05:12

jarofclay


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>
like image 43
Bialecki Avatar answered Dec 10 '22 05:12

Bialecki