I need to make something similar to this folding tree (only 1 sub-level) menu

I would like to use something like this script

The catch is that the data is stored in mysql. Given that the tree is just an unordered list, I should be able to use recursion in php to get the data and echo the HTML, yes?

Has anyone done this before?