0
Good
And the following I have a table categories and another table products at this time when creating the product I select the category to which it belongs by selectbox only now I have the need to associate a products to various categories I would like to know what may be the best way to associate the same product to several 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 ;
databases is Myisam
– César Sousa
It is possible to do with
MyISAM
also, but would be linked to a "Model" in PHP. In more relational databases (asinnoDB
) you would use the1:N
(one-to-Many), but could also use Many-to-Many something like: https://netbeans.org/images_www/articles/73/javaee/ecommerce/data-model/many-to-many.png– Guilherme Nascimento
Then it will be better to convert the database to innoDB and better ?
– César Sousa
Ok so how could I put a php model keeping the same structure I have in the above database
– César Sousa
I already have backoffice and front-end at this time I do the Insert but only for a category through selectbox wanted and implement for more than one category
– César Sousa
Yes César, I understand, I really wanted to tell you that you would need a table with the categories and one with the products, the back-end (which is different from backoffice) and the front-end (which is html, javascript) would be examples of how to do the process.
– Guilherme Nascimento
Can you help me create that I really need to make that system
– César Sousa
Good evening Caesar, it really is a system that takes a certain amount of time to develop and still formulate this as a good answer. It’s not that I don’t want to, it’s that right now I won’t be able to do something really functional in a little while. But I promise to see if I can buy some time and if I’m really capable of creating something useful :)
– Guilherme Nascimento
One solution I was thinking of was to insert an array with the categories in the article column
– César Sousa