For example
Table A (category)
label_id Label_name
1 Badminton
2 Basketball
3 Football
4 Pingpong Ball
b table
ID label_id UID
1 1 1
2 2 1
3 3 1
4 2 2
5 4 2
6 1 3
7 4 3
C table
UID name Sex
1 Three men
2 Li Shiju
3 Harry Male
4 Zhaoliu
Now, the user clicks on a table value to display the records of the C table in table B and displays the value of table B.
For example, the user clicks on the Badminton in Table A (label_id is 1), according to table B that has a UID of 1 and 3 likes badminton (label_id 1 is 1 and 3), then displays all the properties of the C table (UID 1 and 3) Zhang San and Harry, And show all Zhang San and Harry like it (according to the B table). The requirements show the following results:
1, Zhang San male badminton basketball Football
2, Harry male Badminton Soldier Pong Ball
I'm using a thinkphp. How do I get it?
Reply to discussion (solution)
It can be understood that I want to know which ones like badminton, show everyone who likes badminton, and show them all the sports they like.
$sql = "Select C.*,group_concat (a.label_name) as sport from a INNER join B in a.label_id=b.label_id INNER join C on b.uid=c. UID WHERE b.uid in (SELECT b.uid from a INNER JOIN b to a.label_id=b.label_id WHERE a.label_id = 1) GROUP by UID "; M ()->query ($sql);
Good cow, ox man!!