SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Los Angeles
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with db layout

    Hey,

    I am geting started on my first real database project, and I have a couple of questions.

    I am making a table for articles in a magazine. My question is, concerning the images that accompnay a story, should I use a difernt column for each image, like image1, image2, image3, or can (or should) I put the three images in one column together? (The amount of images will probably vary with each story).

    Also, I want to use the primary key from one table in this new table, so all I have to do is use the same column name right?

    i am using mysql, if that makes a difference
    From here on, it's instinctual...even straight roads meander.

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you say the amount of images varies it is IMO best to put the images delimited by some character into one column and using PHP / Perl to display them afterwards properly.

  3. #3
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Los Angeles
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats what i was thinking, but how would i go about that?
    From here on, it's instinctual...even straight roads meander.

  4. #4
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,290
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Personally, I would create another table that contains the images for an article. I wouldn't put a variable field in a database, but that's just me...
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  5. #5
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can make a second table to store the pictures and a id link, for example:

    First, in your main table make a id field if you don't already have one. Then make a new table to store your pictures, with each having a id number w/ the exact same id number as the corresponding entry in the main table.

    So if you had a user "17", then if they wanted to have a picture you insert it into the picture table with it's link_id number also as "17". And so on. Then to select all the pictures you simply "SELECT * FROM picture WHERE link_id = 17" and you'd get a list of all the pictures.

    It's fast & easy.

    Owen

  6. #6
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Los Angeles
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep it seems like thats the route im gonna go...with a seperate table for the images
    From here on, it's instinctual...even straight roads meander.

  7. #7
    SitePoint Enthusiast anantatman's Avatar
    Join Date
    Apr 2002
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    db normalization..

    read a little bit on database normalization on devshed.com (under mysql)

    it will make it much simpler to create a well planned db that way.
    Rahul Singh, CEO
    http://www.anant.us
    http://www.anant.us/blog/
    http://community.rainbowportal.net/



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
  •