galvin Posted March 25, 2010 Share Posted March 25, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196548-general-question-about-numbers-vs-text-in-code/ Share on other sites More sharing options...
oni-kun Posted March 25, 2010 Share Posted March 25, 2010 Depends on the scale of the project. ID's are much easier to implement and maintain, but WHERE `id`= 3 or WHERE `id` = 'Kentucky' is the same in the end. As for speed, it is negligable. Quote Link to comment https://forums.phpfreaks.com/topic/196548-general-question-about-numbers-vs-text-in-code/#findComment-1031950 Share on other sites More sharing options...
galvin Posted March 25, 2010 Author Share Posted March 25, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196548-general-question-about-numbers-vs-text-in-code/#findComment-1031953 Share on other sites More sharing options...
ignace Posted March 26, 2010 Share Posted March 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196548-general-question-about-numbers-vs-text-in-code/#findComment-1032124 Share on other sites More sharing options...
Mchl Posted March 26, 2010 Share Posted March 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196548-general-question-about-numbers-vs-text-in-code/#findComment-1032142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.