Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Achievements

Name: Noko 2010-08-27 22:43

Alright, so I'm working on a site for a client. It is a bar, and the owner wants to be able to hand out 'achievements' that people can get at the bar that will show up on the website, and people can post to their Facebook. The actual process looks like this:

- She logs on to the admin area and hits the 'create achievement' button.

- She types in an ID for the achievement, a name, and a description. Then she enters in how many tickets for the site to generate.

- The code takes the information stores it, and generates a bunch of 9 digit codes that people can enter into the site to redeem.

-

It is a pretty simple system, but my question is this. What is the best way to store all of this in a MySQL database?

Right now I see two ways, both of which feel wrong.

First one:
----------------------------------------------------------
Unique ID :: Achievement ID :: Name :: Description :: Code
----------------------------------------------------------

In this, all the codes are stored in a single array which I then search and remove the code that is redeemed.

Second one:
----------------------------------------------------------
Unique ID :: Achievement ID
----------------------------------------------------------

In this, I store the name and description in the first two rows, then have one row for each ticket thereafter.

Any ideas on which method might be better? Or if there is a better one I'm too stupid to think of?

Thanks

Name: Anonymous 2010-08-28 22:13

>>14
I'd like to second the "Do not use SQL if you cannot program."  SQL is a programming language.  It is a domain specific language, not a general purpose language (such as C), but it is still an unforgiving and sophisticated tool.

>>6
Throwing an "ID" field in every table is a newbie mistake when designing a database.  It shows that you're not sure where the natural keys are.  Read up on "natural keys".  It helps to understand what you will do with those keys, so read up on "joins" too.


CREATE TABLE achievements (
    a_id integer PRIMARY KEY,
    a_name varchar(200) NOT NULL,
    a_desc text NOT NULL
);
CREATE TABLE codes (
    c_aid REFERENCES achievements (a_id),
    c_code CHAR(9) PRIMARY KEY,
    c_redeemed boolean NOT NULL,
    INDEX (c_aid)
);

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List