dmccabe Posted March 28, 2008 Share Posted March 28, 2008 I am making a form for user to input new account information and am unsure which types to use for the best results. For a telephone number is it best to use a VARCHAR ? What about a block of text? BLOB? Radio buttons which serve as YES/NO ??? Any pointers would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/ Share on other sites More sharing options...
rhodesa Posted March 28, 2008 Share Posted March 28, 2008 There will be a lot of variation based on personal preference, but for the things you listed: Phone: VARCHAR Text: *TEXT (there are a couple different variations of the TEXT type) Yes/No: INT(1) with a 0/1 stored in it Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503177 Share on other sites More sharing options...
mwasif Posted March 28, 2008 Share Posted March 28, 2008 Yes/No: INT(1) with a 0/1 stored in it TINYINT(1) would be fine Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503179 Share on other sites More sharing options...
dmccabe Posted March 28, 2008 Author Share Posted March 28, 2008 excuse my ignorance, but what is the (1) after INT and TINYINT ? is it what I put in the length/value in phpmyadmin? Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503181 Share on other sites More sharing options...
dmccabe Posted March 28, 2008 Author Share Posted March 28, 2008 Just another thought, with the values now being an INT or TINYINT should I be passing the value of 1 or 0 instead of yes or no? Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503190 Share on other sites More sharing options...
dmccabe Posted March 28, 2008 Author Share Posted March 28, 2008 Text: *TEXT (there are a couple different variations of the TEXT type) Sorry I should be asking all the questions at once instead of just as they come. but what do you mean there are a couple of variations of text ? and which one should I be using ? is "*TEXT" an actual type? **EDIT** IGNORE - I see them now TEXT/MEDIUMTEXT/LONGTEXT I have chose long text. Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503195 Share on other sites More sharing options...
aschk Posted March 28, 2008 Share Posted March 28, 2008 Check the mysql documentation for the size limitations of the different TEXT types. I have never needed anything more than TEXT. Also, regarding a yes|no option, you can always use BIT(1) Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503207 Share on other sites More sharing options...
mwasif Posted March 28, 2008 Share Posted March 28, 2008 excuse my ignorance, but what is the (1) after INT and TINYINT ? is it what I put in the length/value in phpmyadmin? Yes Just another thought, with the values now being an INT or TINYINT should I be passing the value of 1 or 0 instead of yes or no? Pass 1 for yes and 0 for No. Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503209 Share on other sites More sharing options...
aschk Posted March 28, 2008 Share Posted March 28, 2008 I should probably point out however that if you want a BIT to come out as an numeric representation you'll need to do the following: SELECT `bitfield`+0 FROM ... You need to +0 to the field that contains the bit to get the numeric representation out of it. note: this is as of 5.0.3 Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503217 Share on other sites More sharing options...
dmccabe Posted March 28, 2008 Author Share Posted March 28, 2008 Thanks guys! One last question, when inputting a monetry amount would you use the type of "DECIMAL" ? Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503243 Share on other sites More sharing options...
mwasif Posted March 28, 2008 Share Posted March 28, 2008 Thanks guys! One last question, when inputting a monetry amount would you use the type of "DECIMAL" ? I use DOUBLE. Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503249 Share on other sites More sharing options...
aschk Posted March 28, 2008 Share Posted March 28, 2008 Use numeric for monetary amounts, e.g. NUMERIC(4,2) will allow you a value up to 9999.99 . It ALSO has the added benefit of doing correct calculations on large numbers as opposed to double/float which suffer from 32bit rounding. Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503322 Share on other sites More sharing options...
fenway Posted March 28, 2008 Share Posted March 28, 2008 Thanks guys! One last question, when inputting a monetry amount would you use the type of "DECIMAL" ? I use DOUBLE. DOUBLE is terrible for monetary values -- floating-point error hell. Check the mysql documentation for the size limitations of the different TEXT types. I have never needed anything more than TEXT. Also, regarding a yes|no option, you can always use BIT(1) In v5+, VARCHAR can be up to 65K -- much, much better than TEXT for about 15 different reasons. And as for yes/no, I question your db design. Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503625 Share on other sites More sharing options...
dmccabe Posted March 29, 2008 Author Share Posted March 29, 2008 I question it too lol but thanks for the help. I am completely new to this php/mysql lark. I have been messing with pre-made scripts for a long time, but this is the first time I have started creating from scratch. Quote Link to comment https://forums.phpfreaks.com/topic/98331-which-types/#findComment-503933 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.