Php Mysql: Retrieving 2 usernames via 2 user id -


hi have 1 problem cant solve. doing pair generator tournament.

i have 2 tables. first table contains usernames , userids. 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 want echo

round 1 john - peter ana - dan  round 2 john - ana dan - peter  round 3 ...  round 4 ... 

can done 1 sql code can both usernames table1 user1_id , user2_id?

to retrieve 1 username via user_id had no problem , working great:

$sql = "select table1.username, table3.won          table1          inner join table3 on table1.user_id=table3.user_id;"; 

i know instead of using user_ids in table2 use usernames, way explained above.

select concat((select username table1 t1 t.user_id=t1.user_id=t.user_id) ,'-',(select username table1 t1 t.user_id=t1.user_id=t.user_id)) table2 t 

or

 select concat(t1.username,'-',t3.username) table2 t2   inner join table1 t1 on t1.user_id=t2.user_id   inner join table1 t3 on t3.user_id=t2.user_id 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -