1

I am trying to reference a query from an array and use it in a cfloop tag and I keep getting an error

Error:

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 tried to use a complex value as a simple one. For example, you tried to use a query variable in a cfif tag.

Code:

<cfquery datasource="datasource" name="valueQuery">SELECT count FROM watermelons</cfquery>
<cfset queryArray = ArrayNew(1)>

<cfscript>
ArrayAppend(queryArray, valueQuery);
</cfscript>

<cfloop query="#queryArray[1]#">
        <!---do stuff--->
</cfloop>

I have also tried (without the pounds):

<cfloop query="queryArray[1]">
            <!---do stuff--->
</cfloop>

which gives this error:

The value of the attribute query, which is currently queryArray[1], is invalid.

1 Answer 1

8
<cfset queryIndex = queryArray[1]>
<cfloop query="queryIndex">
        <!---do stuff--->
</cfloop>

'cause query="" expects a variable name.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.