Best method for categories via php and mysql [closed]

0

I'm creating a system with php + mysql. It's a type of social network.

I'm in the planning part of the database and have a question about the best way to record, for example, the individual's abilities.

Example:

Name: Fulano Age 30 Skills: php, mysql, css

Each "skill" has a specific register, with photo description etc. Therefore, I need the person to enter the 'page' of the skill in question and 'short' or 'follow' and then it will appear in their profile.

I thought about keeping those 'skills' comma-separated in the person's database. So at the time of listing, I use explode () and I can even make each word a link that leads to a selection of people with the same skills etc ... Until then, ok. But to register / edit / delete this data? I do not want the person to write anything there, just add via "enjoy / follow" ... and this is getting complex to execute ... Add ", css" when the person follows "css" is a good strategy, or has some more recommended method?

    
asked by anonymous 13.09.2018 / 01:11

1 answer

1

Use relationships between tables in your favor to solve this problem.

Create a table for skills:

CREATE TABLE habilidades (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    nome VARCHAR(256) NOT NULL,
    descricao TEXT NOT NULL
)

And any other information that habilidades would have, then relate the user to the skill.

CREATE TABLE usuario_habilidade (
    usuario int NOT NULL,
    habilidade int NOT NULL,
    PRIMARY KEY (usuario, habilidade),
    FOREIGN KEY (usuario) REFERENCES SuaTabelaDeUsuario(id)
    FOREIGN KEY (habilidade) REFERENCES habilidades(id)
);

That way, whenever you want to add a skill to the user, just add a record to the usuario_habilidade table.

    
13.09.2018 / 01:42