Instead of actually deleting the array item, you can build up a list of
array items to be deleted and do it AFTER the loop. then, delete from the
BACK ... see modifications below, changed lines marked with ******:

-----Original Message-----
From: Bryan F. Hogan [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 11, 2003 10:19 AM
To: CF-Talk
Subject: ArrayDeleteAt() without using cfbreak

<cfset deletethese="">   ******
<cflock timeout="2" throwontimeout="yes" type="exclusive" scope="session">
        <cfloop from="1" to="#ArrayLen(Session.usersCart)#" index="idx">
                <cfif Request.factory.IsInteger(FORM['NumberOfCartTickets'&idx])>
                        <cfif FORM['NumberOfCartTickets'&idx] IS "0"> ********
                                <!--- <cfset ArrayDeleteAt(Session.usersCart, idx)> 
--->
                        <cfset deletethese = listAppend(deletethese,idx)>
********
                        <cfelse>
                                <cfset 
Session.usersCart[idx][1]=FORM['NumberOfCartTickets'&idx]>
                        </cfif>
                </cfif>
        </cfloop>
        <cfloop from="#listLen(deletethese)#" to="1" step="-1" index="i"> ******
         <cfset arraydeleteat(session.userscart,i)> ******
      </cfloop> ******
</cflock>

Ok all, here is a block of code that recaculates totals in my cart.

Everything works great, except for when I enter 0 in the number of cart
tickets field, I want it to remove that item from the array. Now this is all
cool, except for when you use ArrayDeleteAt() it resizes the array. Normal
practice would be to use <cfbreak> after the delete, however I can't do that
because say you have 3 items in your cart like below:

numberoftickets
1
5
9

and you change the numbers like

numberoftickets
1
0
8

the 3rd item would not get updated because of the <cfbreak>

Anyone got any ideas.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/lists.cfm?link=t:4
Subscription: http://www.houseoffusion.com/lists.cfm?link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Signup for the Fusion Authority news alert and keep up with the latest news in 
ColdFusion and related topics. 
http://www.fusionauthority.com/signup.cfm

Reply via email to