ViaoV Posted January 9, 2008 Share Posted January 9, 2008 I have a question about keeping things efficient, as far as a database structure goes. I need to set up a page which will list several items orginized by catagory/sub catagory. The logical idea would be to setup 3 tables as follows: catagoryTable -catagoryId -catagoryName -parent catagory (could be 0 if its a toplevel catagory) itemTable itemName catagoryId However all items are going to be displayed at the same time. So to accomplish this I'm going to have to make a call to get a list of parent categories, call each one to get a list of subcategories, then call each sub category to get a list of items. The categories have to be editable and the items have to be printed out by category. I have been trying to think of something like using DISTINCT somehow to not have to loop through so many queries. The category numbers are small like 10 parent, 1-5 sub in each, 1-15 items in each. The page will get slightly heavy use though so I was wondering if anyone knows a way to make something like that more efficient. Link to comment https://forums.phpfreaks.com/topic/85141-mysql-structure-and-efficiency-question/ Share on other sites More sharing options...
fenway Posted January 9, 2008 Share Posted January 9, 2008 Yes, you'd need a JOIN for each of the N levels of the hierarchy that you'd want to display... provided that N is small (<5), you're ok. Link to comment https://forums.phpfreaks.com/topic/85141-mysql-structure-and-efficiency-question/#findComment-434556 Share on other sites More sharing options...
ViaoV Posted January 9, 2008 Author Share Posted January 9, 2008 Could you give me a query example? not sure how I would join em Link to comment https://forums.phpfreaks.com/topic/85141-mysql-structure-and-efficiency-question/#findComment-434935 Share on other sites More sharing options...
fenway Posted January 9, 2008 Share Posted January 9, 2008 It's just a self join to the original table using parentID as the join condition. Link to comment https://forums.phpfreaks.com/topic/85141-mysql-structure-and-efficiency-question/#findComment-434969 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.