Jump to content

General question about numbers vs. text in code


galvin

Recommended Posts

Someone told me I should try to use NUMBERS in my code as opposed to text, as much as possible.  In general, does it really make that much of a difference?

 

For example, if  i have an NCAA Tourney bracket submit form, if I store the picks in $_POST variable (for eventual submission into a MySQL database), should I store the picks as "teamids" (like 1,2,3 all the way through 64) or is it fine to store them as the actual team name (i.e. "Kansas," "Kentucky, "Cornell", etc).

 

Sure the "actual name" way is a little more total characters, but it seems like there would be more code involved overall if I used "teamids" (since anytime I wanted to display a user's picks, I would only start with a teamid and would therefore have to query to get the actual team name (presumably stored in a main "Teams" table along with the teamid)

 

I hope this makes sense  :)  If so, let me know your feelings on the subject. I'd really appreciate it.

 

Thanks,

Greg

Link to comment
Share on other sites

Thanks! So if I have a "picks" table with a user field and 63 more fields (one for each of that user's picks throughout the tourney, since there are 63 total game), it would be OK to submit team names directly into that table, rather than "teamids"?

 

It would be a small personal project, just for family and friends, so based on what you said originally, I can't imagine there would any speed gain using ids instead of name. 

 

I know this is a MySQL question, but it's a follow-up and I wanted to ask you because you seem to know your stuff  ;)

 

I think I answered my own question anyway, but feel free to reply with any additional thoughts :)

 

 

Link to comment
Share on other sites

Thanks! So if I have a "picks" table with a user field and 63 more fields (one for each of that user's picks throughout the tourney, since there are 63 total game), it would be OK to submit team names directly into that table, rather than "teamids"?

 

Yes just remember to add indexes if not primary key.

Link to comment
Share on other sites

As for speed, it is negligable.

 

TINYINT (which should be enough for this application) ID takes 1 byte per row, VARCHAR ID takes several times more. This means index created on VARCHAR column will take more space both on disk and in memory, as well as it will be less efficient.

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.