pospan Posted January 28, 2016 Share Posted January 28, 2016 Hello Community, I have some diffuclties about getting the right logic for article management with subcategories. So everything with Categorys is fine. TABLE: articles articleID title content cat_relatedID TABLE: categories catID cat_name On submit it Works fine where in "selection option" I can select the Category for that post. Now I want to extend it with subcategories. TABLE: articles articleID title content cat_relatedID TABLE: categories catID cat_name TABLE: subcategories subcatID subcat_name related_catID Now the problem is how to relate Cats and Subcats in the form where I am adding new Articles and submit it to mysql. Do I need a additional field in the article table subcatID or anything else? My logic is something to make like in Wordpress when adding New posts you have the option to check categories related with that post. <ul class="list-unstyled categorychecklist "> <li><input type="checkbox" value=""> Category 1 <ul class="children"> <li><input type="checkbox" value=""> Subcategory 1</li> <li><input type="checkbox" value=""> Subcategory 2</li> <li><input type="checkbox" value=""> Subcategory 3</li> </ul> </li> <li><input type="checkbox" value=""> Category 2 <ul class="children"> <li><input type="checkbox" value=""> Subcategory 4</li> <li><input type="checkbox" value=""> Subcategory 5</li> <li><input type="checkbox" value=""> Subcategory 6</li> </ul> </li> <li><input type="checkbox" value=""> Category 3 - No subcategories</li> </ul> LINK should look something like this example: mylink.com/category.php?ID=12&sub_ID=15 Image attached is how it looks now. Quote Link to comment Share on other sites More sharing options...
Barand Posted January 28, 2016 Share Posted January 28, 2016 Easiest way is to store all in the category table. The parent id of of top-level categories will be NULL, in subcats it's the id of the parent category TABLE: articles TABLE: categories articleID +------ catID ---+ title | cat_name | content | parentCatID >--+ catID >-----+ Quote Link to comment 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.