Database Data Call Issues

Source: Internet
Author: User
Table Business_circle
Field ID Name parent_id
1 Chaoyang 0
2 Changping 0
3 da Wang Road 1
4 Home Building 1
5 Chaoyang Park 1

$sql 1 = mysql_query ("SELECT * from Business_circle ORDER by ID ASC");
while ($rs 1 = mysql_fetch_assoc ($sql 1)) {
echo $rs 1[' name ']. $rs 1[' parent_id ']. '
';
}
The result of the recall is
Grand Lookout Road 1
Hu Jia Lou 1
Chaoyang Park 1

PARENT_ID is the ID of the parent class
I want to pull out the result is
Tai Wang Road Chaoyang
Hu Jia Lou Chao Yang
Chaoyang Park Chaoyang


Complete code should be how to write, master Help, directly to the complete code, thank you


Reply to discussion (solution)

$rs = mysql_query ("Select.name, b.name as PName from Business_circle A, business_circle b where a.parent_id = b.ID"); ($row = MYSQL_FETCH_ASSOC ($rs)) {  echo $row [' name ']. ' ' . $row [' PName ']. '
';}

Big Brother upstairs thank you, but can't tune out, show blank

The great God wrote the wrong place. Help fill 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"); whi Le ($row = MYSQL_FETCH_ASSOC ($rs)) {  echo $row [' name ']. ' ' . $row [' PName ']. '
';}



I hope I can 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.