in reply to Re^2: Fetch data from DB and put in to Table Tk
in thread Fetch data from DB and put in to Table Tk
now my code is running but output is not correct I am getting 'q' for all label in first row of table (TK) and '1' for all label in the second row of the same table
Yes, I ran it and got the same results as you. I (mistakenly) thought that my $row = $sh2->fetchrow_arrayref provided a fresh instance of $row to push onto the @name array. I confess I'm not really sure what is happening or why. It seems that all entries in the array are the last entry. Perhaps someone else could explain this better.
To get the correct info, I made the change below.
#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect("dbi:SQLite:dbname=users.lite","","", or die "Can't connect"; my $sh2=$dbh->prepare("select code,name from level "); $sh2->execute() or die(); my @name; while (my @row = $sh2->fetchrow_array) { push @name, [@row]; } $dbh->disconnect or die $!; for my $i ( 0 .. $#name) { print "code: $name[$i][0] name: $name[$i][1]\n"; } __END__ *** the program prints code: 001 name: Level1 code: 002 name: Level2 code: 003 name: Level3 code: 004 name: Level4 code: 005 name: Level5 code: 006 name: Level6 code: 007 name: Level7 code: 008 name: Level8 code: 009 name: Level9 code: 0010 name: Level10 code: 0011 name: Level11
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Fetch data from DB and put in to Table Tk
by Anonymous Monk on Jul 09, 2012 at 02:26 UTC | |
by Cristoforo (Curate) on Jul 09, 2012 at 13:19 UTC |