I am not sure if this is the smartest way, but i think it would work
I think you should have a parent column in your categories table.
This will allow you to have a tree based structure that should be fairly easily navigable.
Selecting based on parentID = 0 would give you the top level categories.
To go to the next level of subcategories, select parentID = the current category. Continuing this would allow you to move down through the sub-sub ... sub categories.
I hope this is of some use.