Jump to content

[SOLVED] Best way to create this table (awards)


xoligy

Recommended Posts

Ok im going to try and code an awards page and im working on the mysql table for now but im unsure of the best way to do it. The way that im thinking of at the moment us as follows:

 

id - username - sup1 - sup2 - sup3 - fre1 - fre2 - fre3 - kil1 - kil2 - kil3

 

where 1-3 are ranks 1st to 3rd so if playerA win sup1 and kil1 he gets a 1 in them boxes if at a later date he wins sup1 and then kil3 sup 1 would be 2 and kil1&3 would be 1

 

Would you say thats the best way to do it? or can you think of another?

Link to comment
Share on other sites

If you expect there might be more awards i nfuture, then you should plan your database, so that adding new awards is easy.

 

You will need three tables

 

table users
userID, username

table awards
awardID,awardName

table users_awards
userID, awardID, count

Also create primary key in users_awards table on userID and awardID

 

So if you want award player 1 with award 1 you do

 

INSERT INTO users_awards VALUES (1,1,1) ON DUPLICATE KEY UPDATE count = count + 1

Link to comment
Share on other sites

hmm... going to have to think about this more tomorrow im tired now. but the way i was thinking was just one table with all the info in it for awards then i would query just the userid/name which would return the rewards for that user, the way your suggesting i would need to do a union or join yes? im not that smart lol ive done one of them so far and i only got that working by changing the query from "=" to ">"

 

like i said i'll think about it more when im not as tired and have a smarter head on me lol

Link to comment
Share on other sites

Yes i  see that now yesterday i was really tired lol. I was going to write back earlier but went the shop instead, and thinking about it i think my way would be better as its going to keep the db more compact say the player gets 6 awards in total over x time thats 6 inserts with 6 records my way its just 1 record for the whole thing this is my result:

 

id - username - award1 - award2 - award3 - award4 - award5 - award6

1 - xoligy - 3 -0 -1 - 0- 1 - 1

 

this would be yours

id - award -  count (id is username in this)

1 1 3

1 2 1

1 5 1

1 6 1

 

to me mine seems simpler and easier to understand lol

Link to comment
Share on other sites

Easier to understand? Sure

Simpler? Maybe

More compact? No. (though it may seem so at first)

Easier to add new awards in the future? Hell no!

 

It's up to you really. If you don't expect any new awards to be added later, then your approach will work fine. If on the other hand, there will be more awards added later, you'll have hell of a time doing it. :)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.