I am new to this and am in need of assistance. I need to loop through the shopping cart to look for duplicate stocknumbers. Desired result will be that the item quantity will be increased if stocknumber already exists in the shopping cart. Code to follow:

[CODE]
<cfloop collection="#FORM#" ITEM="VarName">
<cfif VarName NEQ "AddToCart"><!--- nothing for submit form field --->
<cfset stocknum = #VarName#>
<cfset quantity = #FORM[VarName]#>

<CFIF quantity NEQ ""><!--- if there is a Quantity --->
<cfquery name="qryGetItem" datasource="landscape" dbtype="ODBC"><!--- get item info --->
SELECT StockNum, Price, Detail, Note, ShipCode
FROM Item
WHERE StockNum = '#stocknum#'
</cfquery>
<!--- get the length of the array and add one to it --->

<!--- then edit the current quantity which is session.cart[position][2]--->

<!--- else (stocknum is different) --->
<cfif #qryGetItem.RecordCount# GT 0> <!--- if we got a record we'll add next --->
<cfset position = ArrayLen(session.cart) + 1>

<cfloop condition="#stocknum# EQ #session.cart[position][1]#">
<cfset session.cart[position][2] = #FORM[VarName]# + #quantity#>

<cfset session.cart[position][1] = "#stocknum#"><!--- stock number --->
<cfset session.cart[position][2] = "#quantity#"><!--- quantity --->
<cfset session.cart[position][3] = "#qryGetItem.price#"> <!--- price --->
<cfset session.cart[position][4] = "#qryGetItem.detail#"><!--- description --->
<cfset session.cart[position][5] = "#qryGetItem.shipcode#"><!--- shipcode --->
<cfif IsDefined("qryGetItem.note")>
<cfset session.cart[position][6] = "#qryGetItem.note#"><!--- note --->
<cfelse>
<cfset session.cart[position][6] = " "><!--- no note, make blank --->
</cfif>
<!--- set the total cost of all items --->
<cfset current_cost = #qryGetItem.price# * #quantity#>
<cfset session.RunningTotal = session.RunningTotal + current_cost>
</CFLOOP><!--- end of conditional loop --->
</cfif><!--- end recordcount --->
<!--- end of is stocknum is same --->

</cfif><!--- end of if quantity --->

</CFIF><!--- end if not submit --->
</cfloop> <!--- end of the loop of items to add --->
<!--- send the user to the view page --->
<cflocation url="http://10.1.2.22/shop/CartView.cfm" addtoken="YES">