+ Reply to Thread
Results 1 to 6 of 6

Thread: mysql table structure help

  1. #1
    saif7463 is offline x10Hosting Member saif7463 is an unknown quantity at this point
    Join Date
    Jun 2008
    Posts
    30

    mysql table structure help

    Hi everyone,

    Currently I have a table which stores user information and another table that has calendar events. For each calendar event, there are a variable number of rounds (ranging from 2 to 6) in which users earn points. I'm not exactly sure how to store this information.

    Should I just create another table that has columns {userid, eventid, round#, score} to store the results? But then it is somewhat difficult to determine which rounds a particular user missed, (which I suppose I could get around by making a fake user who has a record in every round).

    Or, should I just add more columns to the user table? But in doing so, I wouldn't exactly know how to loop through these columns as rounds of events.

    Any help would be appreciated.

  2. #2
    gomarc's Avatar
    gomarc is offline x10 Elder gomarc is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    USA
    Posts
    511

    Re: mysql table structure help

    Maybe it would be best if you explain a little more what you want to accomplish with what you have so far.

    The community will probably give alternative solutions, and you can chose the best one for you.

  3. #3
    saif7463 is offline x10Hosting Member saif7463 is an unknown quantity at this point
    Join Date
    Jun 2008
    Posts
    30

    Re: mysql table structure help

    Yeah, sorry. I'll give a concrete example of what I'm trying to store.

    So there are members of a team that participate in several competitions. The first competition has 3 rounds. Each round is scored out of 6 points. Most members of the team participate in the competition, and thus have 3 scores associated with the competition. So like, Bob scores 3 points, 5 points, and 6 points on the 3 rounds, respectively (Other members of the team also score some number of points ranging from 0 to 18 total points). Then, a few weeks later, there is another competition with 6 rounds, each round worth 6 points. Again, most members of the team participate, with each member procuring points in the 6 rounds, e.g. Bob scores 5, 6, 3, 1, 0, and 6 points.

    The main purpose of the storage is to allow members, like Bob, to access how he did at different meets and compare his scores with other members of the team.

    At the moment, I have a table with member information (userid, name, email, pass, etc.). And I also have a table of the competitions, or event information (eventid, name, date, description, etc). I just don't know how I should store Bob's scores from the 2 (and counting) competitions.

    What I'm thinking is something like, table "results" with columns: scoreid, userid, eventid, round#, score. And in Bob's case, this would translate to the rows(assuming his userid is 1, and the competitions have id's 0 and 1):

    0, 1, 0, 1, 3
    1, 1, 0, 2, 5
    2, 1, 0, 3, 6
    3, 1, 1, 1, 5
    4, 1, 1, 2, 6
    5, 1, 1, 3, 3
    6, 1, 1, 4, 1
    7, 1, 1, 5, 0
    8, 1, 1, 6, 6

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: mysql table structure help

    Does you event table include the number of rounds?

    You don't need a score id.
    [userid , eventid, round] uniquely identifies the entry so you make that your primary key.
    Nothing is always absolutely so.

  5. #5
    xadrieth is offline x10Hosting Member xadrieth is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    62

    Re: mysql table structure help

    Um, I think you've got the right idea of what you want, but why do you have some 0's inserted into the sample data table where they should not be?

  6. #6
    saif7463 is offline x10Hosting Member saif7463 is an unknown quantity at this point
    Join Date
    Jun 2008
    Posts
    30

    Re: mysql table structure help

    Quote Originally Posted by descalzo View Post
    Does you event table include the number of rounds?

    You don't need a score id.
    [userid , eventid, round] uniquely identifies the entry so you make that your primary key.
    Yeah, I plan to have the number of rounds in the event table.
    Ooh, so in say phpMyAdmin, I just select the radio buttons for primary key for those 3 columns?

    So I assume the above system would work. But, what if I want to have the rounds be named (primarily for the members to better identify the rounds)? Like instead of just 1, 2, 3, they were "Algebra I," "Geometry," and "Algebra II." Should I just introduce another table, "rounds" with columns eventid, round#, name and keep the result table the same?

    Thanks for your help!
    Edit:
    Quote Originally Posted by xadrieth View Post
    Um, I think you've got the right idea of what you want, but why do you have some 0's inserted into the sample data table where they should not be?
    The 0's are for the competition with id 0. It seems fine to me the way I have it.
    Last edited by saif7463; 09-28-2009 at 05:28 PM. Reason: Automerged Doublepost

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  3. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  4. MysQL Query for Master table & child table
    By phpasks in forum Programming Help
    Replies: 8
    Last Post: 08-07-2008, 08:07 AM
  5. Table inside table
    By wizeman in forum Tutorials
    Replies: 4
    Last Post: 07-11-2005, 05:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers