SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru coiL's Avatar
    Join Date
    Sep 2001
    Location
    QLD, Australia
    Posts
    666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile check newbies DB structure

    hello,

    I've only ever really worked with one table at a time while learning php. This time though I'm using 3. It's for a voting script, and I just wanted to make sure that I was on the right track.

    Members Table:
    memID (auto increment, primary key)
    name
    email
    state


    Items Table:
    itemID (auto increment, primary key)
    descript
    author
    addDate


    Votes Table:
    voteDate
    memID (foreign key?)
    itemID (foreign key?)


    I wasn't sure about the foreign key thing, I have no experience in working with more then 1 table.

    thanks
    coiL
    "cradled in the learning curve"

  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)
    most definitely on the right track

    make the pair (memID, itemID) the primary key of Votes --that way, a single member cannot vote for the same item more than once

    presumably you are using mysql, so as far as foreign keys are concerned, unless it's an innodb database, you will have to do foreign key checking yourself

    however, that's no big deal, because your application merely needs to ensure that both memID and itemID are valid id numbers at the time you go to insert the Votes row, and of course they would be, if you code it right

    rudy
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •