I have one table that looks something like this:
id parent_id name
1 0 page #1
2 1 Page #2
3 1 Page #3
4 2 Page #4
*parent_id* is realated to id.
page #4 is a child of page #2
and page #2 is a child of page #1
and so is page #3.
I need a mysql query that can get all children to, say id 1.
Which would return all these pages since all pages “master parent” (lol) is page #1.
You basically have two options:
Using recursion, either in your application logic or in the query, if your RDBMS supports that
Storing left/right values for each node in your tree, which lets you easily find all the sub-tree of a node
Both those options are covered in an excellent article at sitepoint, http://www.sitepoint.com/hierarchical-data-database/ (but it doesn’t cover RDBMS recursion, which yours probably don’t support anyway)