See below.

On Wed, 27 Nov 2002 [EMAIL PROTECTED] wrote:

> See inline.
> 
> 
> ------------------------------------------------
> On Wed, 27 Nov 2002 05:02:16 -0800, "Ramon Hildreth" <[EMAIL PROTECTED]> wrote:
> 
> > Hi, I am not getting any output using the below code.
> > 
> > #!/usr/bin/perl
> > 
> > use strict;
> > use warnings;
> > use DBI;
> > --
> > connecting to database (okay with this, it works)
> > 
> > --
> > my (@centers, $stmt, $sth, $row);
> > $stmt = qq { SELECT group_center FROM places};
> > $sth = $dbh->prepare($stmt);
> > $sth->execute();
> > 
> > #here is the problem area
> > while ($row = $sth->fetchrow_array()) {
> 
> Here you are storing your fetchrow_array to a scalar, which means $row
> contains the number of columns in the select (1), you need to store it
> to an array:
> 
> while (@row = $sth->fetchrow_array()) {

Err, this could be a stupid point, but his select statement is actually
returning only one row.  In my understanding & experience, if he uses $row
= $sth-fetchrow_array() he will get the *value* not the array count back.
I've tested this on my system -- can anybody else confirm that isusual
behaviour?

So, for me the code below works fine:
while (my $val = $sth->fetchrow_array()) {
        push @centers, $val;
        }

Hopefully I'm not mangling DBI in some evil way here, but this type of
structure has worked for me repeatedly in the past....

> > push @centers, $_;
> 
> What is $_ set to here?  You really want to push $row[0] or even the whole array 
>(@row) as you only have one element.
> 
> > }
> > foreach (@centers) {
> > print "$_\n";
> > }
> > I get a blank line for each line, where I would expect to see names of
> > groups from my query. ???
> > 
> 
> http://danconia.org
> 

Reply via email to