Hello Jeff,
thanks for your reply. This is helping me a lot.
you wrote:
> > #!/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?
No they don't - fact is I was not aware. I'll rework this to make it better
you wrote:
> > # 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.
This is a code wrapping error - however I don't need these commends here
anyway.
you wrote:
> > $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.
yes
you wrote:
> $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 = ?';
The $n+1 is bad code writing. It hung in there from a previous version where I
could not get the last line printed. The $n+1 was clearly not the solution
and I should have gotten it out
I agree,
for my $i (1 .. $n) {
is way better
you wrote:
> 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!
You're right
you wrote:
> > $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.
I did not know that, certainly looks a lot better. Fact is I only used $i and
the num column in my sql table to identify the each row. I'll take a look at
this, because something in the back of my mind says there must be cleaner
ways to to this
you wrote:
> > 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.
AHA!!! This is where it really went wrong.
I'll rework my code and let you all know
thanks again, jean
> --
> 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>