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("session.cart">
<!--- 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] = "#form.Type#">
<cfset session.cart[position][2] = "#form.noveh#">
<cfset session.cart[position][3] = "#form.totalestcost#">
<cfset session.cart[position][4] = "#form.Description#">
<!--- 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="View_items.cfm">
------------------------------------------------------------
Any help would be greatly appreciated.
Thanks
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("session.cart">
<!--- 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] = "#form.Type#">
<cfset session.cart[position][2] = "#form.noveh#">
<cfset session.cart[position][3] = "#form.totalestcost#">
<cfset session.cart[position][4] = "#form.Description#">
<!--- 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="View_items.cfm">
------------------------------------------------------------
Any help would be greatly appreciated.
Thanks