Date sent: Mon, 14 May 2001 16:41:41 -0500
From: Gerg Carmack <[EMAIL PROTECTED]>
To: dbi-users <[EMAIL PROTECTED]>
Subject: Re: fetchrow_hashref
> Jonas Ask�s wrote:
> > I want to to this:
> > $SQL = "SELECT * FROM members";
> > my $sth = $dbh->prepare($SQL);
> > $sth->execute;
> > my $record_hash;
> >
> > while ($record_hash = $sth->fetchrow_hashref){
> > print "$record_hash->{first_name} $record_hash->{last_name}\n";
> > }
> >
> > Then I want to search the "$sth" again, and maybe print some other
> > information, like this:
> >
> > while ($record_hash = $sth->fetchrow_hashref){
> > print "$record_hash->{last_name} $record_hash->{company}
> > $record_hash->{e-mail}\n";
> > }
> >
> > My question is:
> > After I've search $sth the first time using the fetchrow_hashref-method, how
> > do I point $sth to the first position in the array again, so I can serach it
> > again?
>
> *Provided* memory and result set sizes permit, you can put the whole
> result set in memory, (as the DBI method fetchall_arrayref does for
> records fetched as refs to arrays,) thus:
fetchall_arrayref can even put it into an array of hashrefs (although
it sounds not intuitive) saying
my $reference_to_an_array_of_hashrefs = $sth->fetchall_arrayref({});
See the docs for details
Bodo
[EMAIL PROTECTED]