Baz has asked for the wisdom of the Perl Monks concerning the following question:
but where I use the following -$dbh = DBI->connect("DBI:mysql:database=$serverDb;host=$serverName;por +t=$serverPort",$serverUser,$serverPass); $sth = $dbh->prepare("SELECT code,number FROM $serverTabl_4 WHERE name + = ? ORDER BY number DESC"); $sth->execute($surname); my $ref; while( $ref = $sth->fetchrow_hashref) { $codes{$ref->{code}} = $ref->{number}; print $ref->{number},"\n"; }
$dbh = DBI->connect("DBI:mysql:database=$serverDb;host=$serverName;por +t=$serverPort",$serverUser,$serverPass); $sth = $dbh->prepare("SELECT code,sum(number) FROM $serverTabl_4 group + by code"); $sth->execute(); while( $ref = $sth->fetchrow_hashref) { # $sum{$ref->{code}} = $ref->{number}; print $ref->{number},"\n"; }
etc,etc....+------+-------------+ | code | sum(number) | +------+-------------+ | 1 | 1087 | | 21 | 606 | | 22 | 77 | | 23 | 26 | | 24 | 84 | | 25 | 43 | | 26 | 14 |
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: using fetchrow_hashref
by merlyn (Sage) on Dec 30, 2003 at 19:45 UTC | |
Re: using fetchrow_hashref
by maverick (Curate) on Dec 30, 2003 at 19:47 UTC | |
by Baz (Friar) on Dec 30, 2003 at 19:55 UTC | |
Re: using fetchrow_hashref
by extremely (Priest) on Dec 30, 2003 at 19:45 UTC | |
by diotalevi (Canon) on Dec 30, 2003 at 20:00 UTC |