Add the same product to several categories

0

Good

And the following I have a table categories and another table products at this point when creating the product I select the category to which it belongs by selectbox only I now have the need to associate a product to several categories I would like to know what can be the best way to associate the same product to various categories.

CREATE TABLE IF NOT EXISTS 'estabelecimentos' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'id_mae' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'titulo' varchar(250) COLLATE utf8_unicode_ci NOT NULL,
'slug' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'link_facebook' varchar(250) COLLATE utf8_unicode_ci NOT NULL,
'link_mapa' text COLLATE utf8_unicode_ci NOT NULL,
'distritos' varchar(255) COLLATE utf8_unicode_ci NOT NULL,
'concelhos' varchar(255) COLLATE utf8_unicode_ci NOT NULL,
'morada' varchar(250) COLLATE utf8_unicode_ci NOT NULL,
'contacto' varchar(250) COLLATE utf8_unicode_ci NOT NULL,
'int_preco' varchar(255) COLLATE utf8_unicode_ci NOT NULL,
'link_site' varchar(255) COLLATE utf8_unicode_ci NOT NULL,
'introducao' text COLLATE utf8_unicode_ci NOT NULL,
'servicos' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'descricao' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'keywords' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'keywords_pesquisa' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'google_verification' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'activo' tinyint(1) NOT NULL,
'pos' bigint(20) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=198 ;
    
asked by anonymous 14.02.2015 / 14:40

1 answer

1

One solution is to use a weak entity for this, assuming the

categorias
----------
categoria_id
categoria_nome

produtos
---------
produtos_id
produtos_nome

categorias_produtos
--------------------
categorias_produtos_id
produto_id
categoria_id

Being that would be

categorias 1 -------- * categorias_produtos * ---------- 1 produtos
    
14.02.2015 / 14:48