Count records in Doctrine

Asked

Viewed 155 times

0

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

I need to count the data from a poll vote table so I need to count the values of a field to do the percentage calculation.

On the table votes I have the field id and the countryside opcao where shows the option example: good , bad , great .

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

How I made this in Doctrine ?

  • Is there any example of code you’re trying to do?

1 answer

0

Use the EntityManager to make the following DQL:

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

You will receive as a result array of arrays. Give a print_r this result to see the returned values.

Don’t forget to change the table name and fields for your case.

  • I’ll try, thank you in advance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.