hmm...probably :)

Guess I didn't look at it closely enough (it was well before my first
cup of coffee...which is now sitting in front of me).

Change:
     green = green + 1;
To:
     green = green + cartArrayName[i].Quantity;

...and same for 'not_green'.

Good catch :)

On Thu, 26 Aug 2004 10:15:00 -0400, Dan O'Keefe <[EMAIL PROTECTED]> wrote:
> Instead of just incrementing the counter, wouldn't he need to add
> cartArrayName[i].Number to the var?
>
> Dan
>
>
> ----- Original Message -----
> From: Charlie Griefer <[EMAIL PROTECTED]>
> Date: Thu, 26 Aug 2004 06:39:17 -0700
> Subject: Re: querying an array?
> To: CF-Talk <[EMAIL PROTECTED]>
>
> (assuming your cart is an array of structures...)
>
>  <cfscript>
>       var green       = 0;
>       var not_green = 0;
>
>       for (i=1; i LTE arrayLen(session.cartArrayName); i=i+1) {
>            if (cartArrayName[i].Type is "green") {
>                 green = green + 1;
>            } else {
>                  not_green = not_green + 1;
>            }
>       }
>  </cfscript>
>
>  On Thu, 26 Aug 2004 11:33:51 +0200, mc <[EMAIL PROTECTED]> wrote:
>  > I've got a shopping cart that is in an array (stored in a session). It looks
>  > like this:
>  >
>  > Item      Quantity     Type
>  > -----------------------------
>  > pepper     2           green
>  > avocado    1           green
>  > carrot     3           not green
>  > eggplant   1           not green
>  > celery     5           green
>  >
>  > What I need to do is figure out the total quantity of "not green" items and
>  > "green" items (in this case, 8 "green" items; 4 "not green" items).
>  >
>  > I'm not at all sure how to go about this, as I've always used databases and
>  > queries to do this sort of thing. Am I out of luck or is there some way to
>  > query the data in an array that isn't too horribly complicated?
>  >
>  > P.S. Please forgive me if this issue has already been dealt with here. I
>  > just took a two year break from CF and my brain is a bit out of shape...
>  >
>  >
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to