Ninjakreborn Posted September 8, 2006 Share Posted September 8, 2006 I have already planned most of my database, but an entire, and very important section of the site, hasn't been planned yet. I am trying to set up something for categories, an idea for a database schema. I have a category, sub-category, and different settings for different types of posts. Meaning there are different things they input based on which category/sub-category they selected when posting an ad. It also shows different things when they are viewed, depending on which ones. Like they have a category, a sub-category, but each sub-category will need to accept different things.The thing I am trying to do, like for instance the category is items, the sub-category for instance would be[b]Items[/b]CouchesBedsDesksRefrigeratorsMicrowavesTVsAir ConditionersPosters/PaintingsDrawers/DressersChairsCDs/DVDsHouseholdElectronicsClothing/JewelrySee for items category they are all the samelikeo Item Title (Adjacent one line text box)o Price (Adjacent one line text box)o Description (Large text box below)that will cover 2 categories.Then I have this setup, for instance once category is[b]Academics[/b]TextbooksNotesCheat SheetsNow the category, then the sub-categories.The textbooks will need information likeo Course number (Adjacent one line text box)o Title of book (Adjacent one line text box)o Price (Adjacent one line text box)Then the notes/cheat sheets will needo Item Title (Adjacent one line text box)o Description (Large text box below)You see, so different categories/subcategories need different things, and on some of them there might be a category, then each sub-category is going to need information, I am having a hard time coming up with a good database schema, can someone offer some advive, personal input something like that.I am thinking about1. individual tables for each thing I need2. Making one big table that will have categorysubcategorythen all the fields there, and it will only fill in the related fields, and only pull the related fields(I think this will be too hard to manage/create),I have to do this to where I can still update it, and change things around later, maybe add more later, or refine them, or change them around, Ihave to start this system off right int he planning stage before I can start building it.Sporting GoodsComputer/AccessoriesBikesCollectibles[b]Events[/b]TicketsConcertsSportsClubsPartiesCharity EventsBar specialsPoker Tournaments[b]Lost and Found[/b]Items foundItems lost[b]Rentals[/b]SubletsParking Quote Link to comment Share on other sites More sharing options...
effigy Posted September 8, 2006 Share Posted September 8, 2006 http://www.phpfreaks.com/forums/index.php/topic,106760.msg427294.htmlhttp://dev.mysql.com/tech-resources/articles/hierarchical-data.html Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 8, 2006 Author Share Posted September 8, 2006 I am adding that to my bag of possibilities on this, but I am still looking for further advice/input, that is on my list, but I am wanting to create a different system somehow, something simpler to manage, simpler mantain, and definitely simpler to impliment. I am thinking of 1 table for reach thing, and just linking them by id number, along the similar lines of what you showed me, just different somehow, any other advice, personal experiences, or ideas are appreciated. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 8, 2006 Share Posted September 8, 2006 Just keep the categorization separate from the data, and then you can do whatever you want with it later. Even if you go the simple parent-child route, as long as you have a reasonable number of levels, even JOINs will solve your problem. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 8, 2006 Author Share Posted September 8, 2006 I am thinking of this so far.a list of categories on one tablea list of sub-categories on another table, but have the id for the cateogry affiliated with the sub-categories.for instance I have all the sub-categories in one table, then have a place for the category id, which is hte category that sub-category falls under. It'll get pretty hairy though, because from there, i have to figure out hte rest of the schema, so still open to any suggestions, personal experiences, opinions, ex-cetera. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 8, 2006 Share Posted September 8, 2006 Just have a single table of categories, child and parent; have the root categories with a NULL parent, and you're done. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 8, 2006 Author Share Posted September 8, 2006 It's not that, it's that each of the sections have to be different. Like each category has a sub-category, but some sub-categories have different data than others, some have different informaiton they need than others, this is what is slowing me down. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 8, 2006 Author Share Posted September 8, 2006 Okhere is what I have, I just want input/advice on how well you think it'll be to mantainok first off, as I said, I have categories, sub-categories, then those sub-categories sometimes have sub-sub categories, each sometimes needing different information for them.ok here is hte current plan I have for my schema, I just have to write up the specifics for it[b]Table Number 1[/b]This will have by category id. I will have the name of the category and category id[b]Table Number 2[/b]I will have a sub-category name, sub-category id, and the category id from the category it is associated with.[b]Table Number 3[/b]This contains all the sub-sub categories. It has the sub-sub category name, the sub-sub category id, the sub-category, and category id's associated with it. [b]Other tables[/b]I have 1 different table for each type of specs. Like I might have a table that has typenamedescriptionthen one that haspricetypedescriptionaddresswhatever, then in those tables have the cat, sub-cat, sub-sub-cat, associated with itAll of this here is making sense but it seems to be getting a little too hairy near the end, any advice? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 8, 2006 Share Posted September 8, 2006 [quote author=businessman332211 link=topic=107360.msg430749#msg430749 date=1157736067]All of this here is making sense but it seems to be getting a little too hairy near the end, any advice?[/quote]#1 Figure out the requirements BEFORE you start defining schema. The sub-sub-category is a newly-revealed requirement.#2 Pay careful attention to advice you get from experts like Fenway. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 8, 2006 Author Share Posted September 8, 2006 [quote]Just have a single table of categories, child and parent; have the root categories with a NULL parent, and you're done.[/quote]I didn't understand that, can you re-explain itDoes it have to do with something similar with what I said I had.Also This was a requirement I just didn't know how to explain it first, this is a ad system, and I know all the requirements, but since I have been planning I am encountering, and thinking, since I took all of your advice on this planning, it's making a world of wonders, I feel after I am done planning totally, I could code/program it in a few days, because I can program lightning fast, what slows me down is when I start to have a problem, and have to learn something, or spend a few days thinking through something, that is when it becomes very very time consuming. This is going to change the way I run my career forever. Quote Link to comment Share on other sites More sharing options...
Zane Posted September 8, 2006 Share Posted September 8, 2006 I think fenway means to put all the categories whether a sub cat or not into the same tableand have a column with it's parent categorysomething likecatID | catName | catParent | specType 0 academics root regItem 1 anAcademicsubCat academics regItem 2 aSubSub anAcademicsubCat regItemI hope that makes sense Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 8, 2006 Author Share Posted September 8, 2006 I am still not grasping how to add in the last part, if it was just category, and sub-category, with all the same information It would be easy to me, but because I have to creaet sub-sub categories for some of the categories, along with each sub-sub category or sub-category has to be ablet o hold information it's making my head spin, I have been brainstorming, I have planned out most of the site, almost all the systems, and programming ideas, so I know everything I need to do, I haven't planned 2 things, this schema, working it within the site, and how I am going to allow them to browse, along with about 100 permission situations I have to create, which is fine, once I get past the schema things will start rolling forward from there. I don't understand fully? Quote Link to comment Share on other sites More sharing options...
fenway Posted September 8, 2006 Share Posted September 8, 2006 OK... here we go. When you're relating categories to their parents, it makes absolutely no difference what "type of information" in in these categories... who cares? You're simply relating two UID, one of the child category, one of the parent category. You can do this recursively forever, so it doesn't matter how many levels down you go. As far as category-specific information, break that out into another table.Think really long & hard about this scenario before you post back... none of the additional information you have provided thus far has any bearing on programming this type of solution. AndyB is right -- try to take it all in first. You won't figure out anything if you're going to rush through it. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 8, 2006 Author Share Posted September 8, 2006 Ok so likeCatID SubCatID SubSubCatID1 itemshit I am really, really confused. I think I understand part of what you are sayingso shit. Totally lost. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 8, 2006 Author Share Posted September 8, 2006 If you mean relating categories, and sub-categories based on id, I knew how to do that, if that's what you mean.but you are saying instead of 1 table with category, then another with sub-category and relate them, but you are saying all in one table.I am picturing something liekTABLE-name- categoryinformationid category subcategoryidThen have the names and id's ???Very confused, I am trying to take all of this in, I know most of mysql, I know about joins, I know about relational databases, and I know all about queries, but I don't understand the format you mean, it sounds like with your idea, I would have an easier time, managing categories, sub-categories, sub-sub-categories, and sub-sub-category specific information where applicable, but I don't understand the theory(or how to do) what you said, it's got me very confused. It makes sense as in putting the category and sub-category into the same table, but I don't understandI do understand the parent/child relationship theory from oop, and javascript, but not how it relates to this:S Quote Link to comment Share on other sites More sharing options...
Zane Posted September 8, 2006 Share Posted September 8, 2006 when you're laying this DB structure outjust completely get the word sub categories out of your headall you need to think about is thatevery category has a parent[quote=fenway]You're simply relating two UID, one of the child category, one of the parent category. You can do this recursively forever, so it doesn't matter how many levels down you go.[/quote]exactlyfor instance you havecategory 1category 2category 3category 4category 5in another column you have their parentsso if category 5 is a parent of category 3.....it's a 'sub-category' of 5 Quote Link to comment Share on other sites More sharing options...
fenway Posted September 8, 2006 Share Posted September 8, 2006 Well, at least I'm getting through to someone... ignoring the PK for the moment, this lookup table simply has two columns, parent_category_uid, and child_category_uid:So if we have a Fruits [1] category, which contains apples [2], oranges [3], and berries [4], when then contain, say, granny smith apples [5], strawberries [6] and blueberries [7], we'd have a categories table with one entry each (UID, name, etc). I've enclosed the arbitrary UIDs in square brackets above for simplicity.So our categories table would have the following records:child_category_uid---parent_category_uid1---NULL2---13---14---15---26---47---4If that doesn't make sense, I really can't help you out. I can't make it any simpler. Sorry. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 8, 2006 Author Share Posted September 8, 2006 Ok, I have an idea of what you mean, I also found out it's only a category/subcategory/informationthere are no 2 levels deep. here is what I am wondering, is this correct, is this what you mean.catid subcatiditem couchesitem bedsitem desksitem refrigeratorevent ticketsevent concertsevent clubsevent sportsevent partiesevent charity events rental subletsrental parkingThen I can continue so on and so forth, is that what you are talking about, the only thing I didn't get was the null value. If this is what you meant, I like the idea so far, then I can just have the sub-category specific information, each set in a different table, then have that table reference the category and sub-category.or something similar, then a master table I guess for posts, that will have damn. Ok I understand how to fashion my categories, my sub-categories. I understand how to set up specific information, now what do I do about the posts. When someone posts something they choose category, sub-category, based on the sub-category they enter the necessary information. Then how to do I get that information together in a post, if someone can see where I am coming from. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 8, 2006 Share Posted September 8, 2006 1) This is still backwards -- you want to set the parent, not the child. That's what the NULL is about. And it doesn't matter how many levels there are.2) Those aren't UIDs.3) You simply link the post with a particular category UID.4) Traversing this table is, of course, the actual work... try and see what you can come up with. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 8, 2006 Author Share Posted September 8, 2006 After a lot of thinking, a lot of planning I created something I can do the programming with pretty easily, and it's a clean system I can update, and change around easily later onTables relating to PostscategoryinformationCategorynameSubcategorynameSETSIn this website I am using sets as a basis for the posts. A general set is a group of related information, and different categories may be set to different sets, it’s the set name, the fields needed within the set, at the bottom it is a list of what things go with what sets. In case if anyone but me ever works on this website, in the future.postset1Related subcats- everything under the item and event categoriesCategorynameSubcategorynameUseridPostidItem TitlePriceDescriptionpostset2Related subcats- lost items only under found categoryCategorynameSubcategorynameUseridPostidItem TitleRewardDescriptionpostset3Related subcats- found items only under found categoryCategorynameSubcategorynameUseridPostidItem TitleDescriptionPostset4Related subcats- everything under the rental categoryCategorynameSubcategorynameUseridPostidItemTitlePriceNumberOfUnitsDescriptionPostset5Related subcats- Everything under the work offered BY students categoryCategorynameSubcategorynameUseridPostidItem TitleWageDescriptionPostset6Related subcats- everything under the work offered TO students categoryCategorynameSubcategorynameUseridPostid ItemTitleWageHoursPerWeekDescriptionPostset7CategorynameSubcategorynameUseridPostidCourse numberTitleAuthorPrice Quote Link to comment Share on other sites More sharing options...
Zane Posted September 8, 2006 Share Posted September 8, 2006 yeah this is backwards...as fenway said[QUOTE]catid subcatiditem couchesitem bedsitem desksitem refrigeratorevent ticketsevent concertsevent clubsevent sportsevent partiesevent charity eventsrental subletsrental parking[/QUOTE]go the other way[CODE]category parentCategoryitem rootrental rootevent rootcouches item beds itemdesks itemrefrigerator itemtickets eventconcerts eventclubs eventsports eventparties eventcharity events eventsublets rentalparking rental[/CODE]and suppose couches had two sub categories....making a 'sub-sub'just had them ascategory - parentleather - couchesfabric - couchesthere's no levels it's just referencingbasketball - sportsbirthday - parties21st birthdays - birthdayand so on Quote Link to comment Share on other sites More sharing options...
fenway Posted September 9, 2006 Share Posted September 9, 2006 You know, if you're just going to come up with your own solution anyway, why ask for the experience of others? Don't get me wrong, if you think your innovative solution will work, then go with it, but trust me, it's completely upside-down and entirely inflexible. 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.