Reputation: 11474
I have created a query in my repository which returns the sum of marks and i have given it an alias. below is the code:-
public function findAllResults()
{
$query = $this->getEntityManager()
->createQuery("
SELECT res, sum(res.marks) as total
FROM CollegeStudentBundle:Results res, CollegeStudentBundle:Student std
WHERE std.id = res.student_id group by std.firstname");
return $query->execute();
}
if i would like to check any field from res I write code as :-
echo "<pre>"; print_r($results[0][0]->getStudentId()->getfirstname()); exit;
Now my problem is I want to print the total as well when i tried this code :-
echo "<pre>"; print_r($results[0][0]->getTotal()); exit;
it gives me error. How Can I access that value. ?
Upvotes: 0
Views: 111
Reputation: 15002
Do a var_dump
on the $result
. I think total
field is outside of the found entities object. So $result[0]['total']
may work.
Upvotes: 1