Categories and Sub Categories


I am working on a catalog that would consist of top level categories and sub categories underneath that. What can I use in PHP that will loop the sub categories so I can have unlimited categories under unlimited categories… lol. For example, I could have Top Level >>> Sub 1 >>> Sub 2 Under Sub 1 >>> Sub 3 Under Sub 2

I was thinking I could use some like

 for ($i = 0; $i < 3; $i++)

but I couldn’t get anything of that sort to work, I tried variations and also put in a variable for the 3 that would equal mysql_num_rows of the database, I am just confused!!

Please help, thanks!