SunQuest
 
           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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 23rd, 2004, 10:54 PM
ladybug ladybug is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 ladybug User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question database design mysql php foreign keys

I am creating my very first database dynamic driven web page. I am sensitive, please be kind.

I want to create a resource section for my bike trails web site.

Resources will have categories such as bike clubs, state parks, bike shops etc.

Each resource "subject will have name, description, url, and state it is located in.

I would like users to be able to choose a category and the state and then display the results of the chosen category for the chosen state.

I have thought and thought and this is what I have come up with for database design


Resource Catgeories Table
resource_cat_ID (primary key, auto inc)
resource_cat_name


Bike Club Table
bike_club_ID (primary key, auto inc)
resource_cat_ID (foreign key)
state_ID (foreign key)
bike_club_name
bike_club_url
bike_club_description

State Table
state_ID (primary key, auto inc)
state_name

I would create a table for each resource "subject" as per Bike Club Table?

Is there a more optimized way to do this?

and how would the query be?

Reply With Quote
  #2  
Old May 2nd, 2004, 03:51 AM
martinig martinig is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 5 martinig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 43 sec
Reputation Power: 0
Database Modelling in UML

This article offers a step by step approach to transform a UML object-oriented class model in a purely relational database.

http://www.methodsandtools.com/archive/archive.php?id=9

Reply With Quote
  #3  
Old May 3rd, 2004, 12:53 PM
Marko Marko is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 Marko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Database desidgn solution

You're almost there.

Simply rename the bike club table to resources and
bike_club_name, bike_club_url and description to resource_name, resource_url, resource_description respectively.

Then the query would be:

SELECT resource_name, resource_url, resource_description
FROM resources
WHERE (value from resource_cat_ID field) = resources.cat_id AND (value from state_ID field) = resources.state_id


You don't have to create a table for each category, you allready store them in Resource Catgeories Table.

Simple as that!!

Reply With Quote
  #4  
Old May 21st, 2004, 06:32 PM
ladybug ladybug is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 ladybug User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question database design - join table to tie it up and another q

Thank-you for your replies.
The article martinig posted was very helpful. I am still trying to wrap my head around the relationships. Heady stuff for someone as directionally challenged as me.

Markos suggestion of putting all the resources in one table also set me on track.

This is what I did.
I revised the tables as follows:

resource table
res_id (pk, auto_inc
res_name
res_url
res_desc

resource categories table
res_cat_id (pk, auto_inc)
res_cat_name

states table
states_id (pk, auto_inc)
states_name

I added a new "join table"
res_rescat_states table

res_id
res_cat_id
states_id

and this worked fine for me.
Is it overkill?

Now to complicate matters I need to add regions.

Each state has several regions. Do I make a regions table? This is confusing because some states have regions that are named the same as others. Do I put a state in it as FK? but I already have states in the "join" table.

How can I do it so if I want to query a region I will get the resource info and state associated?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesDatabase Development > database design mysql php foreign keys


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway