It's me again, on the same problem - any assistance is greatly appreciated as this is becoming an impediment to business at present. [sorry in advance if this email rambles - I'm very tired and this is an old problem now and I'm going in circles]

I have looked thoroughly at the code examples sent through by Janet & Peter and made sure that I am referencing an assigned 1st level loop counter in the nested loop but to no avail.

I've figured out that it is ignoring all but the last range code as it goes through the loop for the user$HHBbasket.

The code below works for the last iteration of range numbers (an array called HHBdistqty which is the distinct list of range codes and associated quantities found in the initial array user$HHbbasket - the user's shopping basket)

Essentially it seems to exit the loop to one of the <@ELSE> statements for all but the last range discount (the last row in the HHBdistqty array). And I can't figure out why. I have put a output array to see how many loops it is doing and it seems to go through each row in the user$HHBbasket looking for the last range number only. ie if there are three different range codes (rnum) next to items in the shopping basket, the <@FILTER> selects those entries, and then the <@DISTINCT> gets just the rows where there is a rnum (range code) and using a <@FOR> loop counts up the quantity of product ordered for each of those range codes (ie over 4 products there may be 7 ordered products under a particular range special) creates HHBdistqty which is the rnum (range code number) and the rqty (quantity for the line items for that discount).

All that works fine. But then the subsequent nested <@ROWS> loop (and yes I've tried using an <@FOR> loop instead with no difference).

Any assistance with this is much appreciated - I've tried my best to make it simple to understand. It really comes down to the loops - the code inside the loops is working properly - if there is only one range code found in the user's basket it correctly figures the discount. In all other cases it will work out only the last range discount. So that's how I know that the code inside the nested loop works properly.

<!-- all this works fine from HERE .... -->

<@ASSIGN 'user$HHBbasket' '@@local$resultSet'>

<@ASSIGN 'local$HHBbasktemp' value="<@FILTER array=user$HHBbasket expr='#rnum>0'>"> <@ASSIGN 'local$HHBbaskdist' value="<@DISTINCT array=local$HHBbasktemp cols='rnum num'>">

<@IFEQUAL <@NUMROWS array='local$HHBbaskdist'> '0'>
<!-- if there are no range codes -->

<@FOR stop=<@NUMROWS array=user$HHBbasket>>
<@ASSIGN 'user$HHBbasket[<@CURROW>,sdisc]' value="<@CALC '@@user$HHBbasket[<@CURROW>,Price] * (1+@@local$tax)' precision=2>">
</@FOR>

<@ELSE>
<!-- if there are range codes -->
<@ASSIGN 'local$HHBdistqty' value="<@ARRAY rows=<@NUMROWS array='local$HHBbaskdist'> cols=2>">
<@ASSIGN 'local$HHBdistqty[0,1]' value="rnum">
<@ASSIGN 'local$HHBdistqty[0,2]' value="rqty">

<@FOR stop=<@NUMROWS array='local$HHBbaskdist'>>
<@ASSIGN 'local$totqty' '0'>
<@ASSIGN 'local$1stctr' value='<@CURROW array=local$HHBbaskdist>'>
        <@FOR stop=<@NUMROWS array=user$HHBbasket>>
                <@ASSIGN 'local$totnewqty' '0'>
<@IF "'@@user$HHBbasket[<@CURROW array=user$HHBbasket>,rnum]' = '@@local$HHBbaskdist[@@local$1stctr,rnum]'"> <@ASSIGN 'local$totnewqty' value="@@user$HHBbasket[<@CURROW array=user$HHBbasket>,Quantity]"> <@ASSIGN 'local$totqty' value="<@CALC '@@local$totqty + @@local$totnewqty'>">

<@ASSIGN 'local$HHBdistqty[@@local$1stctr,1]' value="@@local$HHBbaskdist[@@local$1stctr,rnum]">
                        <@ASSIGN 'local$HHBdistqty[@@local$1stctr,2]' 
value="@@local$totqty">

                </@IF>
        </@FOR>
</@FOR>

@@local$HHBdistqty

<!-- works properly down to HERE.. but then these nested loops only work for the last iteration of the HHBdistqty -->


<@ASSIGN 'local$2ndctr' value='0'>

<@ROWS array="local$HHBdistqty">
<@ASSIGN 'local$2ndctr' value='<@CALC "@@local$2ndctr+1">'>

        <@ROWS array=user$HHBbasket>

<@IF "@@user$HHBbasket[<@CURROW array=user$HHBbasket>,rnum]=''">
<@ASSIGN 'user$HHBbasket[<@CURROW>,sdisc]' value="<@CALC '@@user$HHBbasket[<@CURROW>,Price] * (1+@@local$tax)' precision=2>">

<@ELSEIF "@@user$HHBbasket[<@CURROW array=user$HHBbasket>,rnum] = @@local$HHBdistqty[@@local$2ndctr,rnum]">

<@IF "@@local$HHBdistqty[@@local$2ndctr,rqty] >= @@user$HHBbasket[<@CURROW>,QtyLvl1] AND @@local$HHBdistqty[@@local$2ndctr,rqty] < @@user$HHBbasket[<@CURROW>,QtyLvl2]"> <@ASSIGN 'user$HHBbasket[<@CURROW>,sdisc]' value="<@CALC '@@user$HHBbasket[<@CURROW>,Price] * (1- @@user$HHBbasket[<@CURROW>,PriceLvl1]) * (1+@@local$tax)' precision=2>">

<@ELSEIF "@@local$HHBdistqty[@@local$2ndctr,rqty] >= @@user$HHBbasket[<@CURROW>,QtyLvl2] AND @@HHBdistqty[@@local$2ndctr,rqty] < @@user$HHBbasket[<@CURROW>,QtyLvl3]"> <@ASSIGN 'user$HHBbasket[<@CURROW>,sdisc]' value="<@CALC '@@user$HHBbasket[<@CURROW>,Price] * (1- @@user$HHBbasket[<@CURROW>,PriceLvl2]) * (1+@@local$tax)' precision=2>">

<@ELSEIF "@@local$HHBdistqty[@@local$2ndctr,rqty] >= @@user$HHBbasket[<@CURROW>,QtyLvl3]"> <@ASSIGN 'user$HHBbasket[<@CURROW>,sdisc]' value="<@CALC '@@user$HHBbasket[<@CURROW>,Price] * (1- @@user$HHBbasket[<@CURROW>,PriceLvl3]) * (1+@@local$tax)' precision=2>">

<@ELSE>
<@ASSIGN 'user$HHBbasket[<@CURROW>,sdisc]' value="<@CALC '@@user$HHBbasket[<@CURROW>,Price] * (1+@@local$tax)' precision=2>">
</@IF>

<@ELSE>
<@ASSIGN 'user$HHBbasket[<@CURROW>,sdisc]' value="<@CALC '@@user$HHBbasket[<@CURROW>,Price] * (1+@@local$tax)' precision=2>">
</@IF>

        </@ROWS>

</@ROWS>
</@IF>

thanks,
Garth

bbmedia.com.au
p: 0500 527 000
e: [EMAIL PROTECTED]
PO Box 3543 Wamberal NSW 2260


On 13/09/2005, at 10:05 AM, Peter Dobbs wrote:

Just send me your code block, I'll tell you what is wrong with it.

p.
[EMAIL PROTECTED]

-----Original Message-----
From: Garth Penglase [mailto:[EMAIL PROTECTED]
Sent: Monday, September 12, 2005 7:59 PM
To: witango-talk@witango.com
Subject: Re: Witango-Talk: array help - nested for loop

Thanks Peter, will go through this thoroughly and test with my code to
see what the difference is.
I still can't figure out why my code is doing one iteration but not the
rest.
cheers
gp

bbmedia.com.au
p: 0500 527 000
e: [EMAIL PROTECTED]
PO Box 3543 Wamberal NSW 2260
On 13/09/2005, at 9:53 AM, Peter Dobbs wrote:

############# COPY FROM HERE AND PUT IN YOUR DEV STUDIO
###################

<@! COMMENT="Make Arrays (This could have been results from a database
query">
<@ASSIGN NAME="array1" VALUE='<@ARRAY ROWS="2" COLS="2"
VALUE="1,Hello;2,Goodbye">' SCOPE="request">
<@ASSIGN NAME="array2" VALUE='<@ARRAY ROWS="2" COLS="2"
VALUE="1,Yes;2,No">'
SCOPE="request">


USING @ROWS LOOP<BR>


<@! COMMENT="Initialize First Counter (Not really necessary except when
sloppy and not sure if a value might be present!)">
<@ASSIGN name=array1Counter value="" scope=request>

<@! COMMENT="Begin Looping Through First Array">
<@ROWS array=array1 scope=request>
        <@! COMMENT="Increment the counter for the First Array">
        <@ASSIGN name=array1Counter value="<@CALC '@@request$array1Counter
+1'>" scope=request>
        <@! COMMENT="Clear the counter for the second array (remember, it
will keep going up to 3 and 4 otherwise!)">
        <@ASSIGN name=array2Counter value="" scope=request>
        <@! COMMENT="Begin Looping Through the second Array">
        <@ROWS array=array2 scope=request>
                <@! COMMENT="Increment the counter for the Second Array">
                <@ASSIGN name=array2Counter value="<@CALC
'@@request$array2Counter +1'>" scope=request>
                
                <@! COMMENT="OUTPUT THE VALUES FROM THE ARRAYS">
                <@VAR array1[@@request$array1Counter,2]
scope="request">:<@VAR array2[@@request$array2Counter,2]
scope="request"><BR>
                <@! COMMENT="You can use the <@CURROW> tag in the nested
loop instead of @@request$array2Counter">
        </@ROWS>
</@ROWS>

<HR>
USING @FOR LOOP<BR>


<@! COMMENT="Initialize First Counter (Not really necessary except when
sloppy and not sure if a value might be present!)">
<@ASSIGN name=array1Counter value="" scope=request>

<@! COMMENT="Begin Looping Through First Array">
<@FOR START="1" STOP="<@NUMROWS array=array1 scope=request>" STEP="1">
        <@! COMMENT="Increment the counter for the First Array">
        <@ASSIGN name=array1Counter value="<@CALC '@@request$array1Counter
+1'>" scope=request>
        <@! COMMENT="Clear the counter for the second array (remember, it
will keep going up to 3 and 4 otherwise!)">
        <@ASSIGN name=array2Counter value="" scope=request>
        <@! COMMENT="Begin Looping Through the second Array">
        <@FOR START="1" STOP="<@NUMROWS array=array2 scope=request>"
STEP="1">
                <@! COMMENT="Increment the counter for the Second Array">
                <@ASSIGN name=array2Counter value="<@CALC
'@@request$array2Counter +1'>" scope=request>
                
                <@! COMMENT="OUTPUT THE VALUES FROM THE ARRAYS">
                <@VAR array1[@@request$array1Counter,2]
scope="request">:<@VAR array2[@@request$array2Counter,2]
scope="request"><BR>
                <@! COMMENT="You can use the <@CURROW> tag in the nested
loop instead of @@request$array2Counter">
        </@FOR>
</@FOR>





############# TO HERE ##########################        

-----Original Message-----
From: Garth Penglase [mailto:[EMAIL PROTECTED]
Sent: Monday, September 12, 2005 7:14 PM
To: witango-talk@witango.com
Subject: Re: Witango-Talk: array help - nested for loop

Do you have an example of that please, Janet?
thanks
garth

bbmedia.com.au
p: 0500 527 000
e: [EMAIL PROTECTED]
PO Box 3543 Wamberal NSW 2260
On 12/09/2005, at 4:49 AM, Quicknote wrote:

I didn't look realy closely at your code. but this reminded me a a
problem I
had.
I was nesting <@ROWS> and they would not work.
So I used the ACTION "ForLoop" for the first loop and then my second
<@ROWS>
( inside this LOOP ACTION) would work fine!
I tested this a few times and found it to be pretty consistent?
Now I use the ACTION "ForLoop" every time I want to have nested LOOPS.
Hope this helps Janet

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

Reply via email to