Database Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesDatabase Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 26th, 2002, 04:21 AM
stuie stuie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 39 stuie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 52 sec
Reputation Power: 8
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

Reply With Quote
  #2  
Old April 26th, 2002, 04:24 AM
stuie stuie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 39 stuie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 52 sec
Reputation Power: 8
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...

Reply With Quote
  #3  
Old April 26th, 2002, 08:26 AM
q2ip q2ip is offline
Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: South Africa
Posts: 7 q2ip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to q2ip
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

Reply With Quote
  #4  
Old April 26th, 2002, 08:36 AM
stuie stuie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 39 stuie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 52 sec
Reputation Power: 8
Unhappy can i complicate this further?

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!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesDatabase Development > database design


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek