Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFLoop does not like my Number!

Status
Not open for further replies.

DMAN3021

Programmer
Aug 20, 2002
40
CA
I have a SQL query on my CF page that returns a certain number of recordsets. Now, I am trying to get a cfloop to execute a number of SQLQuery.RecordCount / 2 times (-> do a loop for every 2 records found)

I have set up everything as follows:

<cfset NumberOfRecords=SQLQuery.RecordCount>
...
<cfloop index=&quot;Counter&quot; from=&quot;0&quot; to=&quot;NumberOfRecords&quot;>

I have tried many different alterations to try to get this to work, but every time I get this error message:

&quot;Attribute validation error for tag CFLOOP.
The value of the attribute TO is invalid. The value cannot be converted to a numeric because it is not a simple value.Simple values are booleans, numbers, strings, and date-time values.&quot;

Any Ideas on how I can get CF to see that the variable NumberOfRecords is actually a number value?

Dan...
 
Just a simple suggestion, but have you tried this?

<cfloop index=&quot;Counter&quot; from=&quot;0&quot; to=&quot;#NumberOfRecords#&quot;>

Also, out of curousity, how are you going to account for an odd number recordcount? If your recordcount is 3, CF can't loop 1.5 times...

 
Of course! I always forget those little pound sings...!
-> thanks!

In case of an odd number recordcount, I have added the &quot;step=2&quot; parameter to my loop, and then have a special cfif if there is one or two records left at the end.

I found out afterwards, however, that you can simply use the \ symbol to divide integer values. Where 11\5 = 2, so I could originaly arrange my variable using this symbol

Thanks again for the help, I feel super smart now! :-þ

Dan...
 
No problem!
That's a pretty cool idea for handling the loop, I'll have to remember that.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top