Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^3: Fetch data from DB and put in to Table Tk

by Cristoforo (Curate)
on Jul 08, 2012 at 15:20 UTC ( #980587=note: print w/replies, xml ) Need Help??

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
      Thank you  :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://980587]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-04-22 19:01 GMT
Find Nodes?
    Voting Booth?