Hello all,

based on your comments I've changed the script and it's working fine. Thanks 
for all the input.

The double print was produced by:
        foreach (my @result = $sth->fetchrow_array) {
I've changed this into:
        my @result=$sth->fetchrow_array;
        foreach ($result[0]){

Also I've changed
        for ($i = 1; $i <= $n+1; ++$i ) {
into
        for my $i(1 .. $n) {

I've been looking at my variable declaration following Jeff's remarks. I 
thought 
        my (@sku, @qty, @t_qty); 
could be palaced after 
        for my $i(1 .. $n) {
since I only need them in that part of the program. However when I do so I get 
the following error
        Use of uninitialized value in integer eq (==)
        at ./webstore-rijselect-7-wip.pl line 40.
        Use of uninitialized value in string at ./webstore-rijselect-7-wip.pl 
        line 53.
any ideas?


my current code is
________________________________________
#!/usr/bin/perl
#####################################################
#           webstore-rijselect-6-werkt.pl           #
#####################################################
use warnings;
use strict;

use integer;
use DBI;

my ($dbh, $sth, $n, @sku, @qty, @t_qty);


$dbh = DBI->connect('dbi:mysql:DB','U','PW',  {
       PrintError => 1,
       RaiseError =>1  
});


my $row_total = 'SELECT num FROM nra_slim';
$sth=$dbh->prepare($row_total);
$sth->execute;
$sth->fetchrow_array();
$n = $DBI::rows;

for my $i(1 .. $n) {
        my $sku_compare = 'SELECT sku_srs, aantal FROM nra_slim WHERE num = ?';
        $sth=$dbh->prepare($sku_compare);
        $sth->execute($i);
        my @result = $sth->fetchrow_array;
        foreach ($result[0]) {
        $sku[$i]=$result[0];
        $qty[$i]=$result[1];
        $t_qty[$i]=0;
        if ($i < 2) {
                $t_qty[$i]=$qty[$i];
                }
        else {
                if ($sku[$i]==$sku[$i-1]){
                        $t_qty[$i]= $t_qty[($i-1)] + $qty[$i];
                        if($i==$n){
                                print "$sku[$i]",', totaalaantal is ', 
"$t_qty[$i]\n";
                                }
                        }
                else {
                        $t_qty[$i]=$qty[$i];
                        if($i==$n){
                                print "$sku[$i-1]",', totaalaantal is ', 
"$t_qty[$i-1]\n";
                                print "$sku[$i]",', totaalaantal is ', 
"$t_qty[$i]\n";                          
                                }
                        else {  
                                print "$sku[$i-1]",', totaalaantal is ', 
"$t_qty[$i-1]\n";
                                }
                        }
                }
        }
}


$sth->finish;
$dbh->disconnect;
__________________________________________________
regards, jean

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to