Multi-table join call is a bit complicated. thanks for the help of table goods_area.
Goods_id city area
1 Beijing Dawang Road
Table business_circle
Field id name parent_id
This table is the parent subclass table of the regional business area.
Id name parent_id
1 Chaoyang 0
2 Changping 0
3 Dawang Road 1
The child parent_id of 'dawang path' is the ID of its parent class.
The joined fields of the two tables are a. area = B. name.
$ SQL = mysql_query ("select * from goods_area as a inner join business_circle as B on a. area = B. name order by a. goods_id asc ");
While ($ rs = mysql_fetch_assoc ($ SQL )){
Echo $ rs ['region']. $ rs ['parent _ id'].'
';
}
In this way, you can call the value of parent_id, but I want to call the name value in the condition parent_id = id table business_circle.
The result I want to call is the value of the parent class name of Table B in table a $ rs ['region '].
Do you know how to make it clear? The master directly gave the complete code. thank you.
Reply to discussion (solution)
It may take two cycles to obtain the value of $ rs ['parent _ id'] and call it as a condition. how can I write the master code?
Select c. name, d. * from goods_area as c, (goods_area select * from goods_area as a inner join business_circle as B on. area = B. name) as d where c. id = d. parent_id
Select c. name, d. * from business_circle as c, (select * from goods_area as a inner join business_circle as B on. area = B. name) as d where c. id = d. parent_id
This should be the case. c. name is the name you want.