The relationship of the records in these tables must follow the one to many model that I outlined. So long as you have 1 category id that matches multiple products, then each product has multiple sub categories associated with it then your setup should work for you.
If you do not have multiple sub categories for each item then this will not work correctly. When you are going down the levels of menus each new level must have multiple entries that match it to the previous level. Do you have records like this in your tables?
Based on how you are describing your db and relationships I'm not sure if you will be able to create the menu you are looking for because I'm not sure if your setup follows along with the one to many relationship between these tables. If you have any further trouble with this please post back with a copy of the db in a .sql format in a zip archive so that I can take a look.