Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / General CF Topics / January 2010



Tip: Looking for answers? Try searching our database.

Setting session vars with <cfloop> index counter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ron - 28 Jan 2010 16:12 GMT
I need to set structure variables within an array using the loop
counter.
The form variables being passed are in the format:
op_1
op_2
op_3

I've used form associative arrays to do this in the past
successfully...but I'm having trouble setting these. This is my code:

<cfloop from="1" to="10" index="i">
  <CFSET session.cart[arrayLen(session.cart)].options.op_#x# = #form
["op_#i#"]#>
</cfloop>

It's erroring out as:
==========================================
Invalid CFML construct found on line 117 at column 65.
ColdFusion was looking at the following text:
#

The CFML compiler was processing:

A CFSET tag beginning on line 117, column 12.
A CFSET tag beginning on line 117, column 12.
A CFSET tag beginning on line 117, column 12.

The error occurred in C:\Inetpub\wwwroot\test\cart\cart.cfm: line 117

115 :
116 :      <cfloop from="1" to="10" index="x">
117 :      <CFSET session.cart[arrayLen(session.cart)].options.op#x# =
#ops#>
118 :      </cfloop>
119 :
=============================================

Anyone know what the problem is? Thanks
Bob Dively - 28 Jan 2010 18:37 GMT
> <cfloop from="1" to="10" index="i">
>    <CFSET session.cart[arrayLen(session.cart)].options.op_#x# = #form
> ["op_#i#"]#>
>  </cfloop>

I'd go with:

<CFSET session.cart[arrayLen(session.cart)].options["op_" & i] = form["op_" & i] >

(Assuming that "op_#x#" in your example is supposed to be
"op_#i#".)

Signature

Bob Dively  |  I used to be indecisive, but now I'm not sure...

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.