I have one problem that I can't solve. I am doing pair generator for tournament.
I have two tables. The first table contains the usernames and userids. The second table contains match_id, round, user1_id, user2_id
Table 1
user_id username
21 John
22 Peter
23 Ana
24 Dan
Table 2
match_id round user1_id user2_id
1 1 21 22
2 1 23 24
3 2 21 23
4 2 24 22
.
.
.
And I want to echo
Round 1
John - Peter
Ana - Dan
Round 2
John - Ana
Dan - Peter
Round 3
...
Round 4
...
Can it be done with only one SQL code so I can get both usernames from Table1 for user1_id and user2_id?
To retrieve only one username via user_id I had no problem and its working great:
$sql = "SELECT table1.username, table3.won
FROM table1
INNER JOIN table3 ON table1.user_id=table3.user_id;";
I know that i could instead of using user_ids in Table2 just use usernames, but I would like to do it this way like I explained above.