UnknownPlayer Posted October 31, 2011 Share Posted October 31, 2011 I have categories and sub-categories, related with sub_cat 0(parent) or with cat id(sub-cat), now articles are in sub-cats, cant be in parent cat, now i need to select all articles from parent category,that means to select from all sub-cats of that parent categorie. And articles are related with sub-cats. Can someone help me ? Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/ Share on other sites More sharing options...
fenway Posted November 1, 2011 Share Posted November 1, 2011 What? Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/#findComment-1283892 Share on other sites More sharing options...
UnknownPlayer Posted November 1, 2011 Author Share Posted November 1, 2011 Example: i have these categories(table categories): - Cars (id = 1, sub_cat_id = 0) - IT (id = 2, sub_cat_id = 0) - Other (id = 3, sub_cat_id = 0) sub_cat_id is 0, becouse these are parent categories And in "Cars" category i have these sub cats(table categories): - Mercedes (id = 10, sub_cat_id = 1) - BMW (id = 11, sub_cat_id = 1) - VW (id = 12, sub_cat_id = 1) - BMW (id = 11, sub_cat_id = 1) sub_cat_id is 1, becouse these are child categories of category "Cars" (id = 1) And articles are(table articles): - c200 (id = 1, cat_id = 10) - e200 (id = 2, cat_id = 10) - s500 (id = 3, cat_id = 10) cat_id is 10, becouse "Mercedes" cat id is 10(child category) in table categories. Now i need to select all articles from parent category "Cars" (id = 1) Can someone help me ? Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/#findComment-1283917 Share on other sites More sharing options...
UnknownPlayer Posted November 1, 2011 Author Share Posted November 1, 2011 Any help ? Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/#findComment-1284068 Share on other sites More sharing options...
laffin Posted November 1, 2011 Share Posted November 1, 2011 First u need to build a hierarchy. Whether this is stored within the db or u build it dynamically. than u can use this list of ids to pull the articles Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/#findComment-1284075 Share on other sites More sharing options...
UnknownPlayer Posted November 1, 2011 Author Share Posted November 1, 2011 Can you give me example how u mean that ? Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/#findComment-1284094 Share on other sites More sharing options...
mikosiko Posted November 2, 2011 Share Posted November 2, 2011 this presentation posted by fenway in the "The MYSQL sticky" long time ago is a must to be read... around slide 48 and up apply to your case. http://www.slideshare.net/billkarwin/sql-antipatterns-strike-back Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/#findComment-1284133 Share on other sites More sharing options...
UnknownPlayer Posted November 2, 2011 Author Share Posted November 2, 2011 Can you give me example, i dont get ? Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/#findComment-1284294 Share on other sites More sharing options...
UnknownPlayer Posted November 2, 2011 Author Share Posted November 2, 2011 I mean code for my problem if you can ? Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/#findComment-1284302 Share on other sites More sharing options...
fenway Posted November 2, 2011 Share Posted November 2, 2011 If you're looking for code for your entire problem, you're in the wrong forum. Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/#findComment-1284432 Share on other sites More sharing options...
UnknownPlayer Posted November 3, 2011 Author Share Posted November 3, 2011 Oh, then this is half-help-forum. Thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/250190-get-all-articles-from-parent-category/#findComment-1284742 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.