Relationship of tables using FK's [closed]

-1

I'm making a system for the user to create an account and select the movies they've watched.

I have a table in MySQL movies to register all the movies on the site and a table generos that is only the genres of movies (action, adventure ...) and wanted to know how to link these tables so I sign up a new genre and

I would also like to know how I will make the films and their information appear on the person's profile so that they can mark what they have watched?

    
asked by anonymous 03.09.2015 / 04:19

1 answer

1

You will need 4 tables, user , movie , genre and / p>

I used it as a reference link

The user links one-to-many in watched movies, movies from 1 to multiple movies watched, genre 1 to multiple movies watched.

The mysql code looks like this:

CREATE TABLE Usuario (
id INT NOT NULL,
nome VARCHAR(45) NOT NULL,
//OUTROS DADOS DO USUARIO
PRIMARY KEY(id)
);

CREATE TABLE FilmeVistos(
id INT NOT NULL,
FOREIGN KEY (idUsuario) REFERENCES Usuario(id),
FOREIGN KEY (idFilme) REFERENCES Filmes(id)
);


CREATE TABLE Filmes (
id INT NOT NULL,
nome VARCHAR(45) NOT NULL,
//OUTROS DADOS DO Filme
PRIMARY KEY(id),
FOREIGN KEY (idGenero) REFERENCES Genero(id)
);

CREATE TABLE Genero (
id INT NOT NULL,
nome VARCHAR(30) NOT NULL,
//OUTROS DADOS DO Genero
PRIMARY KEY(id)
);

//apareça os filmes cadastrados
SELECT * FROM Filmes;

Put this select in a field for the user to tag and insert into the Viewed Movies.

Any questions see the link below to connect to the bank with php.

link

    
03.09.2015 / 07:14