Taylor_1978
07-26-2007, 04:02 PM
Howdy,
I've used JOIN many times before including 3 or more tables but at the moment I am left scratching my head.
These are my tables:
TEAMS:
tid team id number
teamname team's name
PLAYERS:
pin player id number
playername player's name
RELATIONS:
rid relation id
pin player id number
tid team id number
status Captain, Vice-Captain or Player
Okay so basically, all the teams are listed in table "teams" and all the players are listed in "players" - all pretty obvious so far.
Then in table "relations", it records what team a player is in and if they are Captain, Vice-Captain or a Player. The purpose of this relations table is because a player may be a member of two or even more teams.
Now, I've tried numerous different ways of join queries and haven't come up with the right one so far.
If I was to do a query eg. $select = mysql_query("SELECT.... JOIN.. etc);
then
while($row = mysql_fetch_array($select)) {
etc
}
$row[0] should be the team's name and every team should be listed
$row[1] would show the captain's name if the team has one, and if not - it will leave it blank.
But every combination I try doesn't seem to work and I either end up with the team listed multiple times OR teams that do not have captains/players yet don't get listed at all.
Any help much appreciated! :thumbsup:
Taylor.
I've used JOIN many times before including 3 or more tables but at the moment I am left scratching my head.
These are my tables:
TEAMS:
tid team id number
teamname team's name
PLAYERS:
pin player id number
playername player's name
RELATIONS:
rid relation id
pin player id number
tid team id number
status Captain, Vice-Captain or Player
Okay so basically, all the teams are listed in table "teams" and all the players are listed in "players" - all pretty obvious so far.
Then in table "relations", it records what team a player is in and if they are Captain, Vice-Captain or a Player. The purpose of this relations table is because a player may be a member of two or even more teams.
Now, I've tried numerous different ways of join queries and haven't come up with the right one so far.
If I was to do a query eg. $select = mysql_query("SELECT.... JOIN.. etc);
then
while($row = mysql_fetch_array($select)) {
etc
}
$row[0] should be the team's name and every team should be listed
$row[1] would show the captain's name if the team has one, and if not - it will leave it blank.
But every combination I try doesn't seem to work and I either end up with the team listed multiple times OR teams that do not have captains/players yet don't get listed at all.
Any help much appreciated! :thumbsup:
Taylor.