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

Pages: 1-

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 0:32

Name: Anonymous 2010-08-28 0:37

>>2
Good job doing absolutely nothing. Take your sage-is-a-weapon mentality back to the imageboards.

Name: Anonymous 2010-08-28 0:47

>>1
Wow.  It's impressive how much you don't know about SQL.  Tables are sets, not ordered lists.  Go read a intro book, use natural keys, and normalize your database.

Name: Anonymous 2010-08-28 0:57

>>4

I wasn't treating it as such. I think you may have misunderstood the way I wrote it. I totally didn't think about just grabbing all the entries with the same Achievement ID. I knew I was overlooking something. Thanks.

Name: Anonymous 2010-08-28 2:29

+-------------+
| Achievement |
+-------------+
| ID          |
| Name        |
| Description |
+-------------+

+---------------+
| Ticket        |
+---------------+
| ID            |
| AchievementID |
| Code          |
| Redeemed      |
+---------------+

Name: VIPPER 2010-08-28 3:08

>>1
she

Facebook

newline between every sentence

I have seen alot, but o wont even comment on this.

Name: VIPPER 2010-08-28 3:12

>>7

Damn, i forgot to make notice of the email and name fields.

have some JEWS instead.

JEWS

Name: Anonymous 2010-08-28 3:45

>>8

Juice? I love juice!

Name: Anonymous 2010-08-28 5:27

>>7
alot
Fagot.

Name: Anonymous 2010-08-28 7:00

What is the best way to store all of this
Okay, I have some ideas...
in a MySQL database?
... Never mind.

Name: Anonymous 2010-08-28 15:24

>>11

I'd be open to more ideas, that is simply what I'm familiar with.

Name: Anonymous 2010-08-28 17:16

>>4

Been reading up on some of that - I really appreciate it. Data normalization is a very helpful topic. Honestly, I'm a designer, not a programmer (and my client knows this), but she wanted me to program it, so I'm using what I know.

>>6

That looks great. Using two tables makes much more sense, as well as being normalized.

Name: Anonymous 2010-08-28 17:58


| I'm a designer not a programmer

then why are you on /prog/ . Please do not use mySQL if you cannot program. You will do it wrong I guarantee it. Either work with a programmer on this one or use drupal or a cms that will do this for you automatically.

Name: Anonymous 2010-08-28 18:08

>>14

Oh hey look, a pretentious jackass who thinks he owns this board. How cute.

Name: Anonymous 2010-08-28 18:53

>>15
Oh hey look, a dipshit who can't program and came to /prog/ regardless. How usual ;_;.

Name: Anonymous 2010-08-28 18:55

Dear peter,
Sage goes in the email box.

Name: Anonymous 2010-08-28 21:56

>>16

u mad bro? This is a topic about programing, it goes in /prog/.

Name: Anonymous 2010-08-28 21:59

>>3

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)
);

Name: Anonymous 2010-08-28 23:22

>>18
This is not about programming. Writing formulas in an excel spreadsheet is a more intellectually stimulating exercise than anything you will ever do in your life.

Name: Anonymous 2010-08-29 3:01

>>14,16,21
Fuck off, ``faggot''.

Name: Anonymous 2010-08-29 6:18

>>20
I appreciate the sentiment, and I'll agree that this looks nicer on paper. In the real world, you are going to be massively fucked performance wise when the codes table has billions of entries and you are using a nine character primary key. This will also cause problems should you desire to change the schema, and is likely to create integrity issues if OP decides to expand on this system at some point in the future.

Name: Anonymous 2010-08-29 11:02

>>1
She
Are you expecting her to fuck you if you help her?

>>20
I never learned joins so I always do [m]select ... from ... where x in (select ...);[/code]

Name: Anonymous 2010-08-29 13:35

>>24
Looks like you didn't learn [b][i][o][u]BBCode[u][o][i][b] either.

Name: >>25 2010-08-29 13:36

dammit

Name: Anonymous 2010-08-29 13:39

>>26
now you just look silly

Name: ​​​​​​​​​​ 2010-10-25 13:18

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