I don’t know how to ask this, I just started to learn PHP and Mysql, and I’m having a lot of trouble doing something that is easy.
Let’s say I have two tables in Mysql Actors and Movies.
The Actors have ID and NAME
And the Movies also have the same ID and NAME.
In this example, let’s say our actors are 1 Brad Pitt, 2 Edward Norton, and 3, Jack Nicholson
The movies are 1 Fight Club and 2 Ocean’s Thirteen.
Brad Pitt and Edward Norton are in Fight Club,
Brad Pitt is on Ocean’s Thirteen,
And Jack Nicholson isn’t in any of those movies.
How can I link the actors to the movies on my Mysql Database? Also how can I display them using PHP?
I appreciate any help, I am lost in this one! Thanks for your attention!
You can use
JOINSfor this.In a brief intro, lets have another table,
relations. In that, the movies and the actors are related. ThePRIMARY KEYwill be the combination of the bothIDs.Now we can have a relationship table with these two IDs.
This way, Movie 1 will have both actors 1 and 2.
SQL Queries