SELECT
T1.movie_id,
T1.movie_title,
T2.genre_id,
T2.genre_title
FROM
Table3 AS T3
INNER JOIN Table1 AS T1 ON T3.movie_id = T1.movie_id
INNER JOIN Table2 AS T2 ON T3.genre_1 = T2.genre_id
ORDER BY
T1.movie_id
That would return something like this:
movie_id | movie_title | genre_id | genre_title
1 | title_movie_1 | 1 | title_genre_1
1 | title_movie_1 | 2 | title_genre_2
2 | title_movie_2 | 1 | title_genre_1
2 | title_movie_2 | 3 | title_genre_3
3 | title_movie_3 | 1 | title_genre_1
3 | title_movie_3 | 3 | title_genre_3
3 | title_movie_3 | 2 | title_genre_2
Afterwards, you can just loop through all the records; print movie_title if movie_id changed, then print genre_title.
$currentMovie = 0;
while ($row = mysql_fetch_row($result))
{
if($row['movie_id'] != $current_movie)
{
$currentMovie = $row['movie_id'];
echo "Movie: <a href=\"movie/" + $row['movie_id'] + "\">" + $row['movie_title'] + "</a><br />Genre:<br />"
}
echo "<a href=\"genre/" + $row['genre_id'] + "\">" + $row['genre_id'] + "</a><br />"
}