I've been trying a lot of algorithms, including functions inside functions, and so on... But I haven't been able to solve this, hope you can help me.
I have a MySQL Table with categories, each category can have a parent category. Top categories are those whose parent is 0.
id | parent | name | desc
------------------------------------------------
1 | 0 | sportwear| test
2 | 0 | bikes | test
3 | 1 | shirts | more tests
4 | 1 | shoes | ....
5 | 3 | men | ....
6 | 3 | women | .....
AND SO ON....
I would like to have a SELECT element with a list like this
CATEGORIES:
-sportwear
-----shirts
--------men
--------women
-----shoes
-bikes
-morecategories
-etc
And it should have all the categories, and show them with their proper depth.
To get them All we would use something like
SELECT * FROM categories;
To get subcategories from a specific parent we would use something like
SELECT * FROM categories WHERE parent = PARENT-ID-HERE;
How can I make a PHP algorithm to build a select list like the one shown before?