There is not a known way of doing this in MySQL with infinite levels. You could always use n self-joins, but using PHP is probably a better approach.
You can however restructure your db schema, for example using Pre Order Tree Traversal:
Storing Hierarchical Data in a Database
This will increase the complexity and runtime of inserting data, but will make it much easier to fetch a tree or subtree.