in reply to Fetch data from DB and put in to Table Tk
my @name=$sh2->fetchrow_array;That only fetches the first row from the database query. I think you are expecting 11 rows, (from your code below).
foreach my $j(1..11)Yet here you are getting $j for 1 to 11 when your sql query only returns 2 items, (code and name). So, if you examined @name immediately after retrieving the query, there should only be index 0 and 1 for @name.
Update: Boy, was a little wrong about the array however. zentara has the solution.
I think the sql section might be like this and then you would have an array @name with contents like zentara's @name.
Also, likely should index $j from 0 .. 10 instead of 1 .. 11my $sh2=$db->prepare("select code,name from level "); $sh2->execute() or die(); my @name; while (my $row = $sh2->fetchrow_arrayref) { push @name, $row; }
arrays begin with zero, 0, not 1.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Fetch data from DB and put in to Table Tk
by gocpon (Novice) on Jul 08, 2012 at 08:15 UTC | |
by zentara (Archbishop) on Jul 08, 2012 at 11:22 UTC | |
by Cristoforo (Curate) on Jul 08, 2012 at 15:20 UTC | |
by Anonymous Monk on Jul 09, 2012 at 02:26 UTC | |
by Cristoforo (Curate) on Jul 09, 2012 at 13:19 UTC |
In Section
Seekers of Perl Wisdom