http://www.perlmonks.org?node_id=980511


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.

my $sh2=$db->prepare("select code,name from level "); $sh2->execute() or die(); my @name; while (my $row = $sh2->fetchrow_arrayref) { push @name, $row; }
Also, likely should index $j from 0 .. 10 instead of 1 .. 11

arrays begin with zero, 0, not 1.