I have a table containing users, each user has a city. I am using ObHighchartsBundle to display the number of users in each city
this is my code
$em = $this->getDoctrine()->getManager();
$classes = $em->getRepository('MyBundle:User')->findAll();
$data= array();
$stat=array();
foreach($classes as $class) {
$query = $em->createQuery("SELECT COUNT(u) FROM MyBundle:User u WHERE u.city = ?1");
$query->setParameter(1, $class->getCity());
if (!in_array($class->getCity(), $stat)) {
array_push($stat,$class->getCity(),($query->getSingleScalarResult() *1)/1);
}
}
array_push($data,$stat);
I am only getting the number of users in the first city, so seems like my foreach
loop is not working well .. Any help would be appreciated!