We help IT Professionals succeed at work.
Get Started

create tree from mysql using php...

saad220 asked
Last Modified: 2013-12-13
I am trying to create a tree menu like parent & child categories in a hirearchy. but the question is the parent and nodes listed under different rows and the parent should be sorted according to the CatName1(order) and the child should also sort by ChildName(order) before displaying...some help please...

My sql  table is structured like this.

Product name     catName1List   CatName1(order)  childNameList    ChildName(order)
434                  |        Cat1         |          0             |         Child1         |          0
344                  |        Cat1         |          1             |         Child1         |          2
432                  |        Cat2         |          1             |         Child2         |          0
435                  |        Cat2         |          0             |         Child2         |          1
433                  |        Cat3         |          2             |         Child3         |          1

As you can see from the above table structure, i have first parent node should be ordered by CatName1(order), and the child node should be ordered by  ChildName(order), also what exactly i want to achieve from this table is to get like this structure..

Cat 1
 Cat 2
Cat 3
  |____Child H
and so on.
How would i query mySQL to get this result or php script? please help...and then i need to create xml file structure like this...

<Products>product lists</products>
<childNameList>ChildB </childNameList>
<Product name>434 </Product name>
<Product name>344</Product name>
<childNameList>ChildA </childNameList>
<Product name>432 </Product name>
<Product name>435</Product name>
<childNameList>ChildH </childNameList>
<Product name>433 </Product name>

Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE