Relationship of tables using FK’s

Asked

Viewed 260 times

-1

I am making a system that the user create an account and select the movies he has already watched.

I have a table in Mysql movies to register all the movies on the site and a generous table that is only the genres of the movies (action, adventure...) and wanted to know how to link these tables so that I register a new genre and appear on the page of the register of movies in the select of the genre, how do you do that?

I also wanted to know how I’m going to make the registered movies and their information appear on the person’s profile so that they can mark that they watched?

  • 2

    It’s very broad. Try asking more specific questions or using the search to find questions that may already exist. Not to mention that this is a useless comment, I give a hint, look for CRUD. Good luck.

  • 2

    There are several video tutorials on the Internet about basic registration systems, posting any of them here would make the answer look monstrous and would not have the same effect as watching a video. Search for the terms: PHP Mysql CRUD

1 answer

1

You will need 4 tables, the user, film, gender and movies seen.

I used it as a reference https://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html

The user link from one to several in watched movies, movies from 1 to several viewed movies, genre from 1 to several viewed movies.

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;

Place this select in a field for the user to mark and do the Insert in Viewed Movies.

Any questions please refer to the link below to connect to the php database.

http://wiki.locaweb.com/pt-br/Como_conectar_a_um_banco_MySQL_atrav%C3%A9s_de_script_PHP

Browser other questions tagged

You are not signed in. Login or sign up in order to post.