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

Array Problem

Status
Not open for further replies.

nalbiso

Programmer
Aug 31, 2000
71
0
0
US
Hi,

I need some help with a code to append data to an array. When I add a new item to my cart, it just keeps creating a brand new array instead of just adding the item to the existing one.

This is the code:
------------------------------------------------------------
<cfif NOT IsDefined(&quot;session.cart&quot;)>
<!--- create a two dimensional array to store the items in --->
<cfset session.cart = ArrayNew(2)>
<!--- create a variable to hold the total cost of all items in cart
and set it to 0 --->
<cfset session.total_cost = 0>

</cfif>
<!--- get the length of the array and add one to it --->
<cfset position = ArrayLen(session.cart) + 1>

<!--- add the item to the array --->
<cfset session.cart[position][1] = &quot;#form.Type#&quot;>
<cfset session.cart[position][2] = &quot;#form.noveh#&quot;>
<cfset session.cart[position][3] = &quot;#form.totalestcost#&quot;>
<cfset session.cart[position][4] = &quot;#form.Description#&quot;>


<!--- set the total cost of all items --->
<cfset current_cost = form.totalestcost>
<cfset session.total_cost = session.total_cost + current_cost>

<!--- send the user to the view page --->
<cflocation url=&quot;View_items.cfm&quot;>
------------------------------------------------------------

Any help would be greatly appreciated.

Thanks
 
I don't see anything wrong with this code. Is there more to the code on this page? Perhaps session.cart is being overwritten somehow. Either that or I'm looking at the obvious and I just can't see it!

-Tek
 
One guess would be that the <cflocation> is causing the problem. Try commenting it out and see what happens. - tleish
 
Can you set an session variable to hold the array?
Check the variable to see what it holds, maybe you need to set the variable to something generic, and check to see if the array exists. If not, create a new array, else insert the data. Erwin Oosterhoorn
Analyst Programmer,
Roller hockey'er, biker,
ice hockey player/fan.
 
Thanks everyone.

I figured it out on my own. I just had a loop in the wrong place in my code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top