View Single Post
Old 12-02-2011, 08:21 PM   PM User | #91
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I see you have an id field. Presumably that is the id of the user who filled out the bracket, yes? That is, it is a foreign key to your Users or Members table?

So your tables should look like this:
Code:
CREATE TABLE members ( /* or name of your choosing */
    memberId INT PRIMARY KEY,
    memberName varchar(...),
    ...other fields describing the member...
);

CREATE TABLE teams (
    teamId INT PRIMARY KEY,
    teamName varchar(100),
    seeding INT /* optional */
);

CREATE TABLE picks (
    memberId INT REFERENCES members(memerId),
    bracketSlot varchar(10),
    int teamId REFERENCES teams(teamId) 
);
In other words, each pick by each person gets a *separate record*.

And now the PHP code to insert into that table is trivial:

You simply loop through all the fields in the POST that start with "pick" and insert them, along with the member's id and the team he/she picked, into one record in the PICKS table.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
andrewkcohen (12-04-2011)