Re: DBI Help

nobull_at_mail.com
Date: 03/17/04


Date: 17 Mar 2004 11:50:31 -0800


"Brett Baisley" <baisley@hotmail.com.REMOVETHIS> wrote in message news:<r5r5c.117660$IF6.3882593@ursa-nb00s0.nbnet.nb.ca>...

> I was told that for my Perl/CGI assignment to use a foreach loop,

Why? Were you given any other handicaps?

> foreach $row (sth->fetchrow_array) {
>
> }

There are several mistakes there.

$row is iterating over the colums of a single row. I doubt that is what you want.

More likely you mean is:

  while ( my @row = $sth->fetchrow_array) {
     # do stuff with @row
  }

OR

  while ( my $row = $sth->fetchrow_arrayref) {
     # do stuff with @$row
  }

OR

  while ( my ($this,$that,$the_other) = $sth->fetchrow_array) {
     # do stuff with $this,$that,$the_other
  }

> Now what I want to do is add all of the values returned by the query to an
> array.

The Perl function to add to an array is push().

See also the selectcol_arrayref, fetchall_arrayref and selectall_arrayref methods.

The fetchcol_array and fetchcol_arrayref methods are conspicuous by their absense!

> Any suggestions?

Read the DBI documentation.

Never again listen to the person who suggested a for loop.

This newsgroup does not exist (see FAQ). Do not start threads here.