Hi, how to make a category tree in php? Recently I've a table called 'category' and inside containt ID,Name,ParentID.

Please give me a simple example code to do it. Very appreciated if you could help me to solve this problem.

Recommended Answers

simple example code to do it.

Simple example to do what exactly?

Jump to Post

Order your table by parentId, then recurse through the items. The ones without a parent you show in a loop, in every loop, check if there are any children.

Jump to Post

All 5 Replies

simple example code to do it.

Simple example to do what exactly?

To display category and subcategory in <tr> and </tr> format if possible.

Order your table by parentId, then recurse through the items. The ones without a parent you show in a loop, in every loop, check if there are any children.

Can you provide some php code for me to reference? ?

I could, but I suggest you try first. Much better way to learn.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.