0

I'm trying to make a survey like a referundum to know if my neighboors in my small building are for or against a colectif compost to reduce the organics wastes.

For this tool vote I'm using PHP and SQL, my database is build like this:

DBNAME=collectifCompost Table=voteCompost

column1=id PRIMARY AI

column2=user

column3=vote(yes/no/blank)

To build a chart with statistics vote results (% of YES, NO, BLANK..) I want to make a query on my database to count the number of YES NO AND BLANK but I don't know how. Can you help me please?

If you need more information about my code ask me everything.

1

Use:

select   vote, count(*)
from     voteCompost
group by vote;

Now you get the number of rows per vote value.

  • 1
    This will not count the number of null values. – a_horse_with_no_name Nov 17 '15 at 12:31
  • select vote, count("I have to putt a value YES,NO, BLANK here?") from voteCompost group by vote; – Julihan Nov 17 '15 at 12:35
  • Thank you for your help a_horse_with_no_name but I think with PHP I will make a short calcul to return the numbers of blank vote. I hope... – Julihan Nov 17 '15 at 12:37
  • @a_horse_with_no_name I changed the count(vote) into count(*). Now the NULL values are counted. The OP did not mention that vote could be NULL. – Marco Nov 17 '15 at 12:47
  • $reponse = $bdd->query('SELECT COUNT(vote) AS totalYes from compost WHERE vote="yes"'); and the same request for each choice(yes,no,blank). Thank you for your help! – Julihan Nov 19 '15 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.