Please bottom post.... > Steve > > You may want to think of this from a DB perspective. > > Is there a unique key associated with each of these lookups that could prevent duplicate rows being returned? If you are looking up info for a particular person, I would assume you would only want 1 returned and you would want a key within the table to ensure this uniqueness. > > HPH > -Jason
It is reasonable to have a set of data rows for a particular object. > > > > From: "Steve Bertrand" <[EMAIL PROTECTED]> > > Date: 2004/10/05 Tue PM 05:14:41 GMT > > To: [EMAIL PROTECTED] > > Subject: DBI hashref with multiple db rows > > > > I have created a module, and inside one of the Package methods, I have > > the following code: > > > > $href = $getPlanInfo->fetchrow_hashref(); > > foreach my $key (keys %$href) { > > print "$key : $href->{$key}\n"; > > $name = $key; > > $self->{$name} = $href->{$key}; > > } So in the above you want to loop over the result set storing them to the object, this sounds like the perfect use of an array reference stored to the object. Something like: while (my $href = $getPlanInfo->fetchrow_hashref) { push @{$self->{$name}}, $href; } Now $self->{$name} contains a list, similar to what you mention with the indexes below, but let Perl handle that for you. Then you can loop over the list as with any array reference, or index into it similar to any array. foreach my $element (@{$self->{$name}}) { foreach my $key (keys %$element) { print "$key: $element->{$name}\n"; } } HTH, http://danconia.org > > > > Now, in the main program that calls this method, I have the following: > > > > my ($user) = new Accounting::EagleUser(); > > $user->getPlanInfo("steveb"); > > print "$user->{'plan'} $user->{'username'}\n"; > > > > > > What is happening, is that getPlanInfo() takes a single param, (a > > username). It then performs a fetchrow_hashref, creating the keys for > > the user object with the table field names from the db, and the values > > are the actual data from the table row. > > > > However, my problem is that some users have more than one row. I have > > tried for days, playing, reading, etc and you guys(gals) feel like my > > last hope. I can't figure out a way to give the user object multiple > > values for a single key. The output when print only shows the fetched > > row that it got first, and it appears the second is never looked at. > > > > I was thinking that if I implemented something like $self->{$key$i}, > > where $i could be an incremented integer, I'd have what I was looking > > for, but how do I iterate through the DB to the next row using > > fetchrow_hashref to do this? > > > > I really appreciate any insight at all that will help clarify this for > > me, or at least put me back on a path I feel I have wandered waaay off > > of. > > > > Tks! > > > > Steve > > > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>