Veritabanından aşağıdaki dizisini almak nasıl?

0 Cevap php

Ok to make it more clear: I am Using doctrine

Ben bir tablo Markalar ve Ürünleri var

Brand
  id
  name

Product
  id
  name
  brand_id

I have a lot of brands and Products of those brands in the database. I would like to retrieve List of brands(+ count of its products) Grouped by Brand.name's first latter.

ex: 
array( 
   n => array( 
        0 => array('Nike', 4 ),
        1 => array('North Pole', 18) 
        .....
   )
   .....
)

So my question was can this be done with one query in a efficient way. I really don't wan't to run separate queries for each brand.name's first latter. Doctrines "Hierarchical Data" cross my mind but I believe it for different thing?. thanks

0 Cevap