What is the best way to structure a MySQL table in a tree?

2

What is the best way to structure a product table where you have infinite categories and children, such as a tree? So you can do a simple autocomplete search? Thank you

    
asked by anonymous 24.06.2015 / 06:09

2 answers

1

A possible form would be the table for categories ( tb_categorias ) containing the following columns:

  • idCategory
  • idSubCategory
  • categoryname

If idSubCategoria = 0 , it is Parent category, if it is >= 1 then it is Son category, according to the name of each category. >

And in the product table:

  • Product id
  • idCategory (where already has category and subcategory set)

Then just recover data! ;)

    
24.06.2015 / 06:17
0

Tatiana , you can use " Nested Set Model " as it provides very efficient queries where each item has a single parent and zero or more children.

Maybe this might help you.

    
24.06.2015 / 06:19