in reply to Logic problem on loops
while (@rown = $sthn->fetchrow_array())
over the same set of rows in each of the twelve iterations through the months.
So, does the DB schema provide any information to identify which month applies to each of the various rows containing "first" and "second" "predicted" and "realized" values? If so, work that into the query. If not, you can't do the trimester tabulation at all, no matter how good your Perl code is.
If/when you solve that problem, then think of the tabulation this way (it will make the code shorter and easier):
foreach $filiais (@filiais){ # print an html header (you don't need $cnt2 for this) $tf = $trf = $tm = $trm = 0; # set accumulators to 0 foreach $month (1 .. 12) { # query DB for rows of 4 values _for_this_month_ while (@rown = $sthn->fetchrow_array()) { ($fa,$rfa,$ma,$rma) = @rown; $tf += $fa; # and likewise for the other three accumulators } if ( $month % 3 == 0 ) { # true for months 3,6,9,12 ListTrimestre( $tf,$trf,$tm,$trm,$month/3 ); $tf = $trf = $tm = $trm = 0; # reset accumulators to 0 } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Logic problem on loops
by graff (Chancellor) on Apr 21, 2002 at 21:56 UTC |