|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
database design
i dont really know how to explain this, but all you fellas are smart so you should be able to help me out.
im creating a car related site that will have category listings that will items within the categories. im wanting to be able to add categories later on using PHP as a frontend. for example, i might want to have an engine category, with sub items like pistons, cylinder heads, engine blocks. im currently thinking that i will have a table for each category, seeing that i wont have any idea of how many fields will be in each category. the thing is, how can i list the categories if they each occupy a table? i was wondering if anyone had any examples of this sort of thing that i could have a look at? i know that this probably doesnt make much sense. any help is appreciated. cheers |
|
#2
|
|||
|
|||
|
forget to add...
i forgot to say that my current idea is to have a table for each category, and another table to keep the names of the category tables.
so long... |
|
#3
|
|||
|
|||
|
Hey....
I have an idea.. first off, you only need two tables: categories and items. The categories table will hold all of the categories,sub categories, etc...and it can be as deep (i.e. hierarchical) as you like. Here's how youd do the categories table: create table categories ( catId int auto_increment not null, catName varchar(50) not null, parentId int not null default 0, primary key(catId), unique id(catId) ); notice the parentId field? By default its zero, which would mean any categories with 0 are parent categories... For sub categories you just place the id of the parent category into the sub cats parentId field... youd create a function to list the categories, something like this: function showCats($parentId = 0) { // database conn stuff here $result = mysql_query("select catName from categories where parentId = $parentId"; while($row = mysql_query($result)) { // First show the category echo $row["catName"] . "<br>"; // Now call this function with the parent id to get // all of its sub cats showCats($row["parentId"]; } } do you understand how that works? its a recurring function i.e. it calls itself... that way you can add some code to display items... but im sure you get my point ![]() |
|
#4
|
|||
|
|||
|
sounds good, although... i want to assign a persons name to a particular item in a category... for example this person (id437) is an expert at this category... and have the ability for more than one person per item.
for example under category 'engine'.. you would have an item, 'pistons'... ok i want to assign some people to pistons to say that they are piston experts... does that make sense? you sound like you know what your on about... just wondering if you could help me out? cheers mate! |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Database Development > database design |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|