my $sth_1 = $dbh->prepare("SELECT * FROM vote WHERE item_no='$last_item'"); $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]","$row[13]","$row[8]","$row[14]","$row[9]","$row[15]","$row[10]","$row[16]"); #### #### 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;