ballouta Posted May 27, 2009 Share Posted May 27, 2009 Hello What is the correct Data Type for a 'credits' field so no + or - is allowed. For certain logic errors in my code, the credits sometimes are going -2, I will fix my code but i also want the field to accept only Numbers. Please help thank you Quote Link to comment https://forums.phpfreaks.com/topic/159830-solved-un-signed-field-type/ Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 An unsigned int can't be negative. Is that what you're looking for? Quote Link to comment https://forums.phpfreaks.com/topic/159830-solved-un-signed-field-type/#findComment-843177 Share on other sites More sharing options...
ballouta Posted May 27, 2009 Author Share Posted May 27, 2009 Yes, i noticed in my DB that one of teh crediys number is -2, this field type is int(11) how could it accepted this negative number? thanks Quote Link to comment https://forums.phpfreaks.com/topic/159830-solved-un-signed-field-type/#findComment-843306 Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 well int accepts both negative and positive. unsigned int is non-negative. Quote Link to comment https://forums.phpfreaks.com/topic/159830-solved-un-signed-field-type/#findComment-843309 Share on other sites More sharing options...
ballouta Posted May 27, 2009 Author Share Posted May 27, 2009 if i am using phpmyadmin page, is it good to add to this field the: Attribute: unsigned ? thanks Quote Link to comment https://forums.phpfreaks.com/topic/159830-solved-un-signed-field-type/#findComment-843313 Share on other sites More sharing options...
corbin Posted May 27, 2009 Share Posted May 27, 2009 Have you read the responses at all or even made an attempt to find what the unsigned attribute does in either the PHPMyAdmin or MySQL documentation? No offense, but people have told you a few times now. Unsigned essentially means that numbers cannot be negative. For example, the range of an unsigned int is 0 to 2^32-1. With a normal integer, 31 bits would be value, and the least significant bit would denote positive or negative. Therefore, a signed int would be -2^31-1 to 2^31-1. Quote Link to comment https://forums.phpfreaks.com/topic/159830-solved-un-signed-field-type/#findComment-843347 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.