Code:
<?php
$sub = mysql_real_escape_string($_GET['sub']);
if ($_REQUEST['sub']){
$result = mysql_query("SELECT subgamesname FROM subgames s JOIN games g ON g.id = s.game_id WHERE g.gamesname = '$sub'");
 while ($row = mysql_fetch_array($result)) {
printf("%s<br />", $row["subgamename"], $row["subgamename"]);
 }
}
else{
$result = mysql_query("SELECT gamename FROM games ORDER BY gamename");
 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("<a href='games.php?subgame=%s'> %s </a><br />", $row["gamename"], $row["gamename"]);
 }
}
?>
I'm new to joins on MySQL but thought it was probably best for this circumstance. I think I have the code right, I just don't know how to set the foreign key or anything to set up on the db, right now its like this:

Table
games
Row
gamesid
gamesname

Table
subgames
Row
subgamesid
subgamesname

I have Metal Gear Solid listed in the gamesname row, and it displays it as a link, and when they click it, it takes them to games.php?sub=Metal%20Gear%20Solid. From there I want it to list Metal Gear Rising which is in the subgames table under subgames name. I am unsure if I did the code right. Any help?