Op vrijdag 4 november 2005 16:24, schreef Jeff 'japhy' Pinyan:
> > #!/usr/bin/perl
> > #####################################################
> > #           webstore-rijselect-5-werkt.pl
> > #####################################################
> > use warnings;
> > use strict;
> >
> > use integer;
> > use DBI;
> >
> > my ($dbh, $sth, $sta, $sql_een, $sql_twee, $i, $n, @sku,
> > @qty, @t_qty);
>
> You've just made a bunch of "global" variables.  Sure, they're lexicals,
> but you've declared them all to exist in the uppermost scope of your
> program.  Surely they don't all deserve such wide range, do they?
>
> > # create a statement in $sth
> > $dbh = DBI->connect('dbi:mysql:webstore-2','gabala','',  {
> >        PrintError => 1, ### rapporteer fouten via warn()
> >        RaiseError =>1  ### rapporteer fouten via die() });
>
> Unless this was a code-wrapping error, you've got a problem here.  Your
> second comment hides the '});' part of your code.
>
>    $dbh = DBI->connect('DSN', 'user', 'pass', {
>      PrintError => 1,  # comment
>      RaiseError => 1,  # comment
>    });
>
> > $sql_een = 'SELECT num FROM nra_produkten'; # prepare a SQL
> > query with placeholder $sth=$dbh->prepare($sql_een);
> > $sth->execute; $sth->fetchrow_array(); $n = $DBI::rows;
>
> Ugh.  More wrapping errors.
>
>    $sql_een = 'SELECT num FROM nra_produkten';  # NO PLACEHOLDERS!!!
>    $sth = $dbh->prepare($sql_een);
>    $sth->execute;
>    $sth->fetchrow_array;
>    $n = $DBI::rows;
>
> > for ($i = 1; $i <= $n+1; ++$i ) {
>
> Why $n + 1?  I'd think 1 .. $n is sufficient.
>
>    for my $i (1 .. $n) {
>
> >   $sql_twee = 'SELECT sku_srs, aantal FROM nra_slim WHERE num = ?';
>
> I don't speak your native tongue, but have you just named two variables
> $sql_een and $sql_twee, meaning $sql_1 and $sql_2?  If so, that's pretty
> dwaas.  Give you variables more descriptive names!
>
> >   $sth=$dbh->prepare($sql_twee);
> >   $sth->bind_param(1, "$i");
>
> You don't need to quote $i here.
>
> >   $sth->execute;
>
> And you could've just done:  $sth->execute($i).  That would've used $i to
> fill in the placeholder.
>
> >   foreach (my @result = $sth->fetchrow_array) {
>
> That is certainly incorrect.  I think you just want to do:
>
>    my @result = $sth->fetchrow_array;
>
> and dispense with the loop entirely.  Otherwise, you're running the same
> code TWICE (once for each element in @result).
>
> > 1989, totaalaantal is 5
> > 1989, totaalaantal is 5
> > 4121, totaalaantal is 1
> > 4121, totaalaantal is 1
>
> Yup.  Tweemaal.
>
> --
> Jeff "japhy" Pinyan        %  How can we ever be the sold short or
> RPI Acacia Brother #734    %  the cheated, we who for every service
> http://www.perlmonks.org/  %  have long ago been overpaid?
> http://princeton.pm.org/   %    -- Meister Eckhart

-- 
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