Page 1 of 1

Comparing Answers between users

Posted: Wed Aug 17, 2011 3:28 am
by pikerslayer
Basically I've made a simple table full of 20 answers from radio buttons
$q1 = $_POST['q1'];
$q2 = $_POST['q2'];
$q3 = $_POST['q3'];
and so on I wish to compare these values and give a percentage then show the most highest result to the lowest any ideas on the theory?

Re: Comparing Answers between users

Posted: Wed Aug 17, 2011 2:52 pm
by jacek
Well you are presumably storing 1 and 0, You could get the number of 1 answers and compare it to the total.
SELECT
    COUNT(`q1`) AS `q1`
FROM `table`
GROUP BY `q1`
This would give you the number of yes and no resonances.

Try it out and see how far you can get.

Re: Comparing Answers between users

Posted: Fri Aug 19, 2011 9:25 pm
by Kamal
Off-topic, you could do this:
$count = 20;
for($i = 1; $i <= 20; $i++){
    $q{$i} = $_POST["q{$i}"];
}
Then you have all your $q1, $q2, $q3 (etc..) ready to be used :)