Popescu Dan wrote:
Hi,
I have a database table withe the next fields: category_id, parent_id,
category_name.

How can i display all the categories with their subcategories, like this

Category 1
  Category 11
  Category 12
     Category121
Category 2
  Category 21
  Category 22

You need to use a function that lists the children of the passed parent_id, then call it recursively so that it prints a tree. For the initial call, you would pass it the root id, usually 0 or -1.


There is a great Sitepoint article that details how to do this. Read http://www.sitepoint.com/article/hierarchical-data-database

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to