id | name 1 | aaa 2 | bbb 3 | ccc 4 | ccc 5 | aaa 6 | ccc 7 | ccc 8 | aaa 9 | bbb 10 | ccc 11 | aaa
i would like become:
name | count ccc | 5 aaa | 4 bbb | 2
orderby count DESC
i made:
public function getCount() { $q = $this->createQuery('q') ->select('*') ->addSelect('count(q.name) as count') ->groupBy('q.name') ->orderBy('count DESC'); return $q->execute(); }
but if :
foreach ($count as $开发者_Python百科c) { echo $c; }
this show me only first data in table.
how can i make it?
Change your loop to this:
foreach ($count as $c) {
echo $c->count . "\n";
}
edit: a good way to debug this is to change your return to
$q->fetchArray();
and then in your loop
print_r($c);
精彩评论