Database data call problems

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.