Multi-Table Association call, a little complicated, the expert help thanks
Table Goods_area
Field goods_id City area
1 Beijing Grand Lookout Road
Table Business_circle
Field ID Name parent_id
This table is the parent class table for the regional shopping district
ID Name parent_id
1 Chaoyang 0
2 Changping 0
3 da Wang Road 1
Is ' big Hope Road ' is ' Chaoyang ' sub-class parent_id is the ID number of its parent class
The associated field for two tables is A.area=b.name
$sql = mysql_query ("SELECT * from Goods_area as a INNER joins Business_circle as B on A.area=b.name ORDER by a.goods_id ASC ");
while ($rs = Mysql_fetch_assoc ($sql)) {
echo $rs [' area ']. $rs [' parent_id ']. '
';
}
This makes it possible to invoke the value at the parent_id, but I want to invoke the name value of the condition parent_id = ID Table business_circle
And the result I want to turn out is a table $rs[' area ' in table b the value of the parent class name
Don't you know how to speak clearly? Master directly to the complete code, thank you
Share to:
------Solution--------------------
Select c.name,d.* from Business_circle as C, (SELECT * from Goods_area as a INNER joins Business_circle as B on A.area=b.nam e) as D where c.id=d.parent_id
That's what this is, C.name is the name you want.