Count records in Doctrine

0

I need to return the total number of records in a field of a table, and also count the number of records of a given id.

I need to count the data of a poll's table of votes so I need to count the values of a field to calculate the percentage.

In the votes table I have the field id and the field opcao where it shows the example options: good, bad, great.

I need to count how many votes I have in the total of all the options and also count how many votes I have in each opcao .

How do I do this in Doctrine?

    
asked by anonymous 28.09.2015 / 05:24

1 answer

0

Use EntityManager to do the following DQL:

SELECT v.opcao, count(v.id)
FROM Voto v
GROUP BY v.opcao

You will be given an array of arrays . Give%% of this result to see returned values.

Do not forget to change the name of the table and the fields for you.

    
02.10.2015 / 18:36