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

Re^2: Mysql Issues (newb)

by r34d0nl1 (Pilgrim)
on Dec 17, 2004 at 02:13 UTC ( #415529=note: print w/replies, xml ) Need Help??


in reply to Re: Mysql Issues (newb)
in thread Mysql Issues (newb)

Generally the hash structure provides a more effective way to deal with the retrieved data.
I'm still learning the basic of PERL, but I've been using hashes
to deal the data retrieved from the database.
So it would be interesting to use hashes instead of arrays. I really don't know if in your case the use of arrays is mandatory.
but you could do, for example creating a hash like in:
my %rpt = ( ) ;
Then, building the hash with the information in the fields:
while (my @row = $sthNames->fetchrow_array ()) { my $P = \%{$rpt{NAME}{$row[0]}}; $P->{PHONE1} = $row[1]; $P->{PHONE2} = $row[2]; }

And then, when going to use the information, just use the hash you created, like this:
... foreach my $name (keys %{$rpt{NAME}}) { my $P = \%{$rpt{NAME}{$name}}; $html .= qq { <TR> <TD>$name</TD> <TD>$p->{PHONE1}</TD> <TD>$P->{PHONE2}</TD> </TR> }; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://415529]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2019-10-17 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?