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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax to Update an array 1

Status
Not open for further replies.

anastasia

Programmer
Dec 13, 2000
111
GB
Hi, I was wondering if anyone knows the code needed to update an element in an array. The element in the array is that of a quantity field. The code I have so far is as follows:

<CFLOOP index=&quot;rowCount&quot; from=&quot;1&quot; to=&quot;#ArrayLen(session.basket)#&quot;>
<CFOUTPUT>
<CFIF #rowCount# EQ #session.indexAnswer#>

<CFSET session.basket[ArrayLen(session.basket)][9]=form.quantity>
</CFIF>

</CFOUTPUT>

</CFLOOP>

I can find the proper element in the array to update and I am updating it with the form.quantity field but it is not updating the correct element just the last element in the array.

The session.indexAnswer is the arrays index be it 1,1 etc. I know by using the next line of code that this updates the last element's quantity field in the array. I know of an ArrayAppend and ArrayPrepend but these update the beginning and end of arrays? I haven't come across any others that seem to be what I am looking for?

Thanks.

 
Your problem is in the line of code where you set the quantity:

<CFSET session.basket[ArrayLen(session.basket)][9]=form.quantity>

You're specifying to set the last element of the array to the quantity from the form.

You would instead want to set the array element associated with your loop index. Try substituting the ArrayLen(session.basket) with rowcount. Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top