Categories and subcategories in a single SELECT

0

I have the following table structure:

CATEGORIAS
id
titulo

SUBCATEGORIAS
id
id_categoria
titulo

I wanted to know if there is a way to bring all categories and subcategories at once into a single select as a two-dimensional array sort of like this:

$categorias = array(
   [0] => array(
      ['id'] => 1,
      ['titulo'] => "Categoria 1",
      ['subcategorias'] => array(
         [0] => array(
            ['id'] => 1,
            ['titulo'] => "Subcategoria A"
         ),
         [1] => array(
            ['id'] => 2,
            ['titulo'] => "Subcategoria B"
         ),
         [2] => array(
            ['id'] => 3,
            ['titulo'] => "Subcategoria C"
         )
      )
   ),
   [...] <= E assim por diante...
)

Note: I use PHP with PDO.

    
asked by anonymous 14.03.2018 / 15:33

0 answers