SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    In Cyber Space!
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding one thing into alot of groups!

    Hi,

    This is what I'm having a problem with! I'm just starting to use DBs in web design and I'm working on this one that has a person or speaker which could talk about any multiple topics up to like 18. If this person talks about 5 topics, how would I structure my DB to be able to add this person into those 5 of 18 topic groups. Now when I query the DB he will show up under those 5 topic groups?

    I was thinking doing a row for each topic (so there would be 18 of them not including our data rows) and putting a 0 or 1 into every topic. I know there has to be a better way to do this!

    Thanks!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    speaker table

    topic table

    speaker-topic table

    the first two are obvious

    the speaker-topic table has two fields: the ids of the speaker and topic which are related

    called a relationship or association or junction table

    to add a speaker to 5 topics, you will end up inserting 5 rows into the speaker-topic table

    there are one or more rows for each topic that a given speaker speaks on

    there are one or more rows for each speaker that speaks on a given topic

    the speaker-topic table implements the many-to-many relationship

    rudy
    http://rudy.ca/

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    In Cyber Space!
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks r937! It totally makes sense what your talking about, now all I have to do is work up the code to do it

    Thanks again!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •