Comparing Answers between users

Ask about a PHP problem here.
Post Reply
pikerslayer
Posts: 2
Joined: Sun Jul 31, 2011 3:53 am

Comparing Answers between users

Post 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?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Comparing Answers between users

Post 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.
Image
User avatar
Kamal
Posts: 123
Joined: Fri May 06, 2011 10:45 am
Contact:

Re: Comparing Answers between users

Post 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 :)
Post Reply