lagrenouille has asked for the wisdom of the Perl Monks concerning the following question:
This is how I have been doing it, and it works... however I'm sure there is a more efficient method of doing it... I just can't nut it out.my $sth_1 = $dbh->prepare("SELECT * FROM vote WHERE item_no='$last_ite +m'"); $sth_1->execute(); while (my @row = $sth_1->fetchrow_array()) { #### Define variables from the mySQL output. my $description = $row[4]; my %results = ("$row[5]","$row[11]","$row[6]","$row[12]","$row[7]","$r +ow[13]","$row[8]","$row[14]","$row[9]","$row[15]","$row[10]","$row[16 +]");
I don't think this is working... It is also very ugly and innefficient as with the first part of my question. Could anyone explain why it isn't working ? (the values are not being given data to store... uninitialised)#### Turn the output into percentages. my $total = $results{"$row[5]"} + $results{"$row[6]"} + $results{"$row +[7]"} + $results{"$row[8]"} + $results{"$row[9]"} + $results{"$row[10 +]"}; $results{"$row[5]"} = ($results{"$row[5]"} / $total) * 100; $results{"$row[6]"} = ($results{"$row[6]"} / $total) * 100; $results{"$row[7]"} = ($results{"$row[7]"} / $total) * 100; $results{"$row[8]"} = ($results{"$row[8]"} / $total) * 100; $results{"$row[9]"} = ($results{"$row[9]"} / $total) * 100; $results{"$row[10]"} = ($results{"$row[10]"} / $total) * 100;
Edit: Added <code> tags. larsen
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading data from mySQL into hashes and manipulation of hashes
by simeon2000 (Monk) on Aug 30, 2002 at 12:46 UTC | |
|
Re: Reading data from mySQL into hashes and manipulation of hashes
by reyjrar (Hermit) on Aug 30, 2002 at 12:47 UTC | |
|
Re: Reading data from mySQL into hashes and manipulation of hashes
by CubicSpline (Friar) on Aug 30, 2002 at 12:55 UTC | |
|
Re: Reading data from mySQL into hashes and manipulation of hashes
by cfreak (Chaplain) on Aug 30, 2002 at 14:18 UTC | |
|
Database Design
by lagrenouille (Acolyte) on Aug 30, 2002 at 14:48 UTC | |
by tommyw (Hermit) on Aug 30, 2002 at 15:07 UTC | |
by lagrenouille (Acolyte) on Aug 30, 2002 at 15:11 UTC | |
by CubicSpline (Friar) on Aug 30, 2002 at 19:09 UTC |