Problem with tables

Asked

Viewed 49 times

1

I’m trying to make a series site, only I’m suffering to hit the logic of the tables, first I’ll explain how I want it to work, the person enters the site, there are the series that pulls the following information from the bank id(int), id_temp(int, id_temporada), nome_serie, lancamento, audio, thumb_serie so far so good, then my link that gives access to the chosen series is like this <a href="seriado.php?id=1&id_temp=1">Ver Série</a>, ai on the page seriado.php I created two more tables in the bank, which are episodios and temporadas, on the table episodios I have the following fields id(int), id_temp(int), nome_episodio, sinopse, link_video and in the table temporadas I have the following fields id(int), id_temp(int), nome_temporada(int)

my select are like this (series) select * from series, (episodios) select * from episodios where id = $id or id_temp = $id_temp, (temporadas) select * from temporadas where id = $id or id_temp = $id_temp index.phpseriado.php

  • Do you want to take the movies related to a series? For example, if you access a series called "The PHP search" list the episodes of that series?

  • Yes, the spisodios and seasons

  • Okay, on the chart, these episodes have a relationship with the series, in this case a Foreign key, or something that says this episode belongs to such a series?

  • I used the id_temp for that, I edited the question, I think it was better what I tried to do, and what I hope

1 answer

1

Best Normalize the Bank As Follows:

Table Series : Idserie Nome

As the spisodium is of the season, so:

Time Table: Idtemporada, Idserie(FK)

The episode is linked to the season, so:

Table Episodios: Idepisodios, Idtemporada(FK)

So if you want to select could use the example innerJoins:

Select s.* from series as Inner Join temporadas t ON s.Idserie = t.Idserie left Join Episodios E on t.Idtemporada = e.Idtemporada.

I used left Join at the end due to the possibility of a series with season but no episodes yet.

That’s one way to do it.

  • sorry bro, what does it mean FK ?

  • Foreing key - foreign key. Each table has a single key (Primary key). When they are used in other relationship tables, they change their name and are called foreing key (fk) https://www.w3schools.com/sql/sql_foreignkey.asp

Browser other questions tagged

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