I guess this is almost to basic to answer. You should find some tutorials on SQL.
I'l try to explain a bit. I hope you understand something from it.
==DATABASE PART==
TABLE movie
- id (auto_increment number)
- name
- some other fields that are UNIQUE to the movie
TABLE actor
- id (auto_increment number)
- name
- some other fields that are UNIQUE to the actor
TABLE cast
- id (auto_increment number)
- actor_id
- movie_id
- some other fields that are UNIQUE to the roll (like the character they're playing)
cast.actor_id refers to actor.id
cast.movie_id refers to movie.id
I gave table cast it's own id, cause one actor can play multiple rolls in the same movie. If that weren't possible you could instead make the combination of movie_id and actor_id unique.
If you know the movie_id and want to know who're the actors (id):
SELECT
*
FROM cast
WHERE movie_id = '5'
You can also select the actor's name simultaniously using a JOIN:
SELECT
actor.id,
actor.name
FROM cast
LEFT JOIN actor
ON actor.id = cast.actor_id /* connect the fields */
WHERE
cast.movie_id = '5'
That'll give you a list of all actors and corresponding id's.
==PHP PART==
$conn = mysql_connect( $host, $user, $password ) or die( "can't connect" );
mysql_select_db( 'movies', $conn ) or die( "can't select db: ".mysql_error( $conn ) );
$query = "SELECT blahblahblah (see DB part, the last query)";
$result = mysql_query( $query, $conn ) or die( "can't do query: ".mysql_error( $conn ) );
while( $row = mysql_fetch_assoc( $result ) ){ // keep picking a row from the result and put it in $row (until we run out of rows)
echo "<a href='".$_SERVER['PHP_SELF']."?actor=".$row['id']."'>".$row['name']."</a>";
}
That'll give you a list of all actors acting in a movie, shown in HTML as links to a page about the actor.