[thelist] mySQL Query help
Tom Dell'Aringa
pixelmech at yahoo.com
Thu Jun 10 16:29:10 CDT 2004
Hi, need help with a query. I have two tables: "games" and "team". In
games there is are two fields that are team IDs. I want to get the
team NAME from the team table using the two stored IDs in games
(foreign keys). I've not done queries in a long time and I'm really
rusty so i cannot remember how to do it.
Here's my code:
@mysql_select_db($dbname) or die( "Unable to select database");
$query = "SELECT * FROM games";
mysql_query($query);
$result = mysql_query($query) or die(mysql_error());
$num = mysql_numrows($result);
$i=0;
while ($i < $num)
{
$teamA = mysql_result($result,$i,"teamAID");
$teamB = mysql_result($result,$i,"teamBID");
// get team names??
$a1 = mysql_result($result,$i,"a1");
$a2 = mysql_result($result,$i,"a2");
$a3 = mysql_result($result,$i,"a3");
$b1 = mysql_result($result,$i,"b1");
$b2 = mysql_result($result,$i,"b2");
$b3 = mysql_result($result,$i,"b3");
// print our results here
++$i;
}
----------------
So what I want is the team NAME for teamA and teamB instead of the
foreign key IDs stored in games. I thought it was some kind of inner
join but I am lost.
The field name in team is 'name'.
Thanks
Tom
=====
http://www.Pixelmech.com/ - read my latest blog posting!
http://www.crossandthrone.com/ - Eternal Life
John 3:16
More information about the thelist
mailing list