herghost Posted February 26, 2012 Share Posted February 26, 2012 Hi all, Its been a while since I looked at PHP and I have forgotten some basics What I am trying to achieve is display category names, sub categories and results into a list <ul id="nav"> <li><a href="#">Main Cat</a> <ul> <li><a href="#">Sub Cat 1</a> <ul> <li><a href="#">result</a></li> <li><a href="#">result</a></li> </ul> </li> <li><a href="#">Sub Cat 2</a> <ul> <li><a href="#">result</a></li> <li><a href="#">result</a></li> </ul> </ul> </li> What would be the best way to organise my database? Have everything in one entry like: main_id / sub_id / listing_id / listing_name or separate them into a table for cats, one for sub cats and what parent it belongs to, then a table for the listings linking to the sub cat it belongs to? I have confused myself no end on how then to display the results, so any help with would be gratefully received! Thanks Dave Quote Link to comment https://forums.phpfreaks.com/topic/257827-some-logic-help-please/ Share on other sites More sharing options...
Anon-e-mouse Posted February 26, 2012 Share Posted February 26, 2012 Hello Dave, Personally I would structure the database in the following way... Table 1 - Holds your main categories, their descriptions etc. Table 2 - Holds the sub-categories, their descriptions etc which is linked in with `mainCatID` or something similar. Table 3 - Holds the listings themselves with the information and a `subCatID` field or something like it. So you can then iterate through your main categories. Whilst you do that you can then iterate through the subcategories and within that the listings for that specific subcategory. Main Category (Loop) -> Sub Category (Loop) -> Listing (Loop). It isn't the cleanest way you could do it but certainly something to then build on. Hope it helps. Quote Link to comment https://forums.phpfreaks.com/topic/257827-some-logic-help-please/#findComment-1321532 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.