Database data call problem table & nbsp; business_circle field & nbsp; id & nbsp; name & nbsp; parent_id & nbsp; & nbsp; 1 & nb database data call problems
Table business_circle
Field id name parent_id
1 Chaoyang 0
2 Changping 0
3 Dawang Road 1
4 Hujia Building 1
5 Chaoyang Park 1
$ Sql1 = mysql_query ("select * from business_circle order by id asc ");
While ($ rs1 = mysql_fetch_assoc ($ sql1 )){
Echo $ rs1 ['name']. $ rs1 ['parent _ id'].'
';
}
The call result is
Dawang Road 1
Hujia Building 1
Chaoyang Park 1
Parent_id is the id of the parent class.
The result I want to call up is
Dawang Road Chaoyang
Hujia building Chaoyang
Chaoyang Park
How should I write the complete code? Thanks for sharing the following:
------ Solution --------------------
$rs = mysql_query("select.name, b.name as pname from business_circle a, business_circle b where a.parent_id = b.id");
while($row = mysql_fetch_assoc($rs)) {
echo $row['name'] . ' ' . $row['pname'] . '
';
}
------ Solution --------------------
I wrote something wrong. help me make it up.
$rs = mysql_query("select a.name, b.name as pname from business_circle a, business_circle b where a.parent_id = b.id");
while($row = mysql_fetch_assoc($rs)) {
echo $row['name'] . ' ' . $row['pname'] . '
';
}
Hope to help you.