Assign an article in more than one category php

0

I have to insert a database in the database assigned to more than one category, how could I do this? In case it would appear the category options available in my bank and I would select them with a checkbox

    
asked by anonymous 07.07.2016 / 19:10

1 answer

0

In this case your tables in the database should have more or less these structures:

|--------artigo----------|  
|id - titulo - nome - etc|  
|------------------------|  

|---categoria---|  
|id - nome - etc|  
|---------------|  

|-------artigo_categoria------|  
|id - id_artigo - id_categoria|  
|-----------------------------|  

This gives you an article that has more than one category. When doing select just use a inner join to associate.

select * from artigo
inner join artigo_categoria on (artigo.id = artigo_categoria.id_artigo)
inner join categoria on (artigo_categoria.id_categoria = categoria.id)
    
07.07.2016 / 19:39