Any idea what is wrong with the syntax of this CFLOOP ?

cgttsp01
cgttsp01 used Ask the Experts™
on
I am getting an error using this CFLOOP statement:
<CFLOOP query="Query_AB" from="1" index="i" to="#ListLen(INumber)#" > 

Here is the error message.
Any idea why?

/********************************************************/
Error Diagnostic Information
Attribute set validation error in tag CFLOOP

The tag has an invalid attribute combination: the most likely attribute combination is

Required attributes: 'FROM,INDEX,TO'. Optional attributes: 'STEP'.
Other possible combinations are
Required attributes: 'COLLECTION,ITEM'. Optional attributes: None.
Required attributes: 'INDEX,LIST'. Optional attributes: 'DELIMITERS'.
Required attributes: 'QUERY'. Optional attributes: 'ENDROW,STARTROW'.
Required attributes: 'CONDITION'. Optional attributes: None.
The error occurred while processing an element with a general identifier of (CFLOOP), occupying document position (8:1) to (8:60).
 
/*******************************************************/
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
When you loop through a query, you don't specify your index.  You're actually combining an index loop and a query loop.

You could write your loop like so:

<CFLOOP query="Query_AB">
</cfloop>

or if you wanted to do an index loop, you could loop through the query like so:

<cfloop index="i" from="1" to="recordcount.Query_AB">
</cfloop>

and you could get elements in the query using the following:

Query_AB.column1[i], Query_AB.column2[i]

Where Column1 and Column2 are the names of the columns.

Author

Commented:
Your suggestion for: <cfloop index="i" from="1" to="#ListLen(Query_AB.INumber)#"> works fine and it corrected the error.

However, the loop is only getting the first record from the query 'Query_AB'.

Any idea on why it is not looping all records?

Commented:
For the "to" paramater, you should use "#recordcount.Query_AB#" and not "#ListLen(Query_AB.INumber)#"

C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Commented:
<cfloop index="i" from="1" to="Query_AB.recordcount">
  Query_AB.<column>[i]
</cfloop>

Commented:
i missed out #.

<cfloop index="i" from="1" to="#Query_AB.recordcount#">
 Query_AB.<column>[i]
</cfloop>


Commented:
Hi there,

If u want to loop on Query then

to use the query !!!
<cfloop query="queryname">
 #queryname.clomunname#
</cfloop>

to use the list !!!
<cfloop index="i" from="1" to="#listlen(inumber)#">
 #listgetat(inumber,i)#
</cfloop>

now it depends waht u wanna use

let me know

K'Rgds
Anand
actually it's #queryname.columnlist#

What is the action the looping is supposed to be doing, and how many records are returned by the query?

Also I find it usefull to declare a value for listlen(inumber) and then make sure it's greater than 0, before taking the cfloop action.

It all depends on the recordset and what actions you are doing with each loop.

The more you tell, the more we can help.

btw http://livedocs.macromedia.com has all the cold fusion documentation from CF5 on.
If you're trying to loop through only a certian number of records in the query, to do something like "Next 15", or basically output on the top 25 records or soemthing, then you want to use startRow and endRow.

So from this:

<CFLOOP query="Query_AB" from="1" index="i" to="#ListLen(INumber)#" >

You get this:

<CFLOOP query="Query_AB" startRow="1" endRow="#ListLen(INumber)#">

This will loop through from the first to however many ListLen(INumber) evaluates to.
actually it's safer to not loop straight the listlen value of inumber

I would do it like this.

<cfparam name=endrow default=0>

Then down where we do the looping

<cfif listlen(inumber) gt 0>
   <cfset endrow = listlen(inumber)>
</cfif>

<CFLOOP query="Query_AB" startRow="1" endRow="#endrow#">

And this way you are making sure that there is valid data, and it won't error out if there is nothing in that field.

Author

Commented:
thanks Anand.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial