Forums

This topic is locked

multiple name ID's

Posted 12 Feb 2007 15:52:40
1
has voted
12 Feb 2007 15:52:40 dan mit posted:
Hi,
I'm trying to make some kind of match system, like PvP, but I have limited knowledge of php and mysql (not so limited I dont understand anything I am a computer science student so I have some programming experience) so im trying to make it as simple as possible but I have hit a slight snag. I want to display each match and have the id's of the teams involved replaced with there names, I try to do it with 'where' statements but it doesnt appear to get any data from the database. What can i do here?

Replies

Replied 12 Feb 2007 16:54:17
12 Feb 2007 16:54:17 Roddy Dairion replied:
In you sql statement join the student detail's table and the match table using the student id.
e.g
<pre id=code><font face=courier size=2 id=code>
select student_table.student_name, match_table.match from student_table
inner join match_table on student_table.student_id = match_table.student_id
</font id=code></pre id=code>
The above will interogate both the student_table and the match_table and will return just the matching student_id in both tables.

Edited by - roders22 on 12 Feb 2007 16:54:35
Replied 12 Feb 2007 18:21:23
12 Feb 2007 18:21:23 dan mit replied:
Ok I have tried using the inner join and it didnt really work.
What I have is 2 'team' id's in one table and both these id's are both linked to one table that holds data about the team, name, members, etc.
Then I need to have both of the id replaced by their names, each at the same time.

eg.
This is what I have now:

| Match ID | Team_1_id | Team_2_id | Playdate |
| 1 | 1 | 2 | 'date'
| 2 | 3 | 4 | 'date'

This is what I would like:

| Match ID | Team 1 | Team 2 | Playdate |
| 1 | Team A | Team B | 'date'
| 2 | Team C | Team D | 'date'

The formating is a bit screwed.
That make it a bit more clear?

Edited by - Mondan on 12 Feb 2007 18:24:33
Replied 12 Feb 2007 18:40:11
12 Feb 2007 18:40:11 Roddy Dairion replied:
Then you do 2 inner join its simple.
<pre id=code><font face=courier size=2 id=code>
Select `Team 1`.team, `Team 2`.team, match_table.playdate
From match_table Inner Join team_table AS `Team 1` ON `Team 1`.team_id = match_table.team_1_id
Inner Join team_table AS `Team 2` ON `Team 2`.team_id = match_table.team_2_id
</font id=code></pre id=code>
There you go this is how the code shoud be.
It would have been easier if you gave me the exact table name and field name in them.
But try to replace the field name and table name where needed.

Edited by - roders22 on 12 Feb 2007 18:41:54
Replied 12 Feb 2007 18:56:26
12 Feb 2007 18:56:26 dan mit replied:
Wahey, Thanks alot managed to get it to work.

Reply to this topic