Page 1 of 1
percentages
Posted: Thu Aug 08, 2002 7:25 pm
by phice
I'm making a polling system, and i'm wondering what I could do to find the percentage of each number of votes for each answer..
If you need more information, just tell me.
Posted: Thu Aug 08, 2002 7:54 pm
by fatalcure
lol, huh? need more info

Posted: Thu Aug 08, 2002 8:33 pm
by protokol
total up all the votes for the poll .. then take the number of votes for each question and divide by the total votes for ALL the questions. Then multiply by 100.
Code: Select all
<?php
// votes for questions
$q1_votes = 4;
$q2_votes = 5;
$q3_votes = 8;
$tot_votes = $q1_votes + $q2_votes + $q3_votes;
echo "Question 1 has $q1_votes (".($q1_votes/$tot_votes)*100."%)<br>";
echo "Question 2 has $q2_votes (".($q1_votes/$tot_votes)*100."%)<br>";
echo "Question 3 has $q3_votes (".($q1_votes/$tot_votes)*100."%)";
?>
Posted: Thu Aug 08, 2002 11:55 pm
by phice
protokol wrote:total up all the votes for the poll .. then take the number of votes for each question and divide by the total votes for ALL the questions. Then multiply by 100.
Code: Select all
<?php
// votes for questions
$q1_votes = 4;
$q2_votes = 5;
$q3_votes = 8;
$tot_votes = $q1_votes + $q2_votes + $q3_votes;
echo "Question 1 has $q1_votes (".($q1_votes/$tot_votes)*100."%)<br>";
echo "Question 2 has $q2_votes (".($q1_votes/$tot_votes)*100."%)<br>";
echo "Question 3 has $q3_votes (".($q1_votes/$tot_votes)*100."%)";
?>
Thanks very much... Here's a little modify ^_^
Code: Select all
<?php
// votes for questions
$q1_votes = 4353454;
$q2_votes = 34534535;
$q3_votes = 84543454345;
$q4_votes = 1;
$tot_votes = $q1_votes + $q2_votes + $q3_votes + $q4_votes;
echo "Question 1 has $q1_votes (".number_format((($q1_votes/$tot_votes)*100),2,'.','')."%)<br>";
echo "Question 2 has $q2_votes (".number_format((($q2_votes/$tot_votes)*100),2,'.','')."%)<br>";
echo "Question 3 has $q3_votes (".number_format((($q3_votes/$tot_votes)*100),2,'.','')."%)<br>";
echo "Question 4 has $q4_votes (".number_format((($q4_votes/$tot_votes)*100),2,'.','')."%)<br>";
?>