Hello:
I have a table with three columns. They are:
category_id PK auto_increment
category_name
parent_id
I need to sort that data so sub-categories appear underneath the correct category.
The data looks like this:
category_id category_name parent_id
1 Hardware 0
2 Software 0
3 DVD Movies 0
4 Printers 1
5 Memory 1
6 Drama 3
7 Sci Fi 3
8 Simulation 2
9 Educational 2
The root category is parent_id = 0.
The subcategories is parent_id = category_id.
The category list should appear like this:
Hardware
- Printers
- Memory
Software
- Simulation
- Educational
DVD Movies
- Drama
- Sci Fi
You can see that the categories with parent_id = 1 is the same as category_id =1.
I am having a hard time creating the category list to appear like the one above.
Can someone help me out?
Thanks in advance.