adam291086 Posted March 10, 2009 Share Posted March 10, 2009 How do i return a Bit value from a database with php. Quote Link to comment https://forums.phpfreaks.com/topic/148842-mysql-bit-and-php/ Share on other sites More sharing options...
premiso Posted March 10, 2009 Share Posted March 10, 2009 As long as your mysql table is setup that way: $result = mysql_query("SELECT `colname` FROM `tablename` WHERE `somecol` = 'someval' LIMIT 1"); $val = mysql_result($result, 0); echo "Value returned $val"; If you plan on returning more than one row, look into mysql_fetch_assoc or mysql_fetch_row. They have examples. Quote Link to comment https://forums.phpfreaks.com/topic/148842-mysql-bit-and-php/#findComment-781649 Share on other sites More sharing options...
adam291086 Posted March 11, 2009 Author Share Posted March 11, 2009 problem is i am using ez_sql.php class and when i look at the array the female section doesnt contain anything even though it is set to be 1 in the database. What should the bit(1) = if the answer is yes i am female Array ( [idUser] => 1 [username] => Adam [password] => plowman [title] => Mr [forename1] => Adam [forename2] => [surname] => Plowman [addressLine1] => [addressLine2] => [town] => [postcode] => [secondEmail] => [personalUrl] => [photo] => [female] => [postcodeStart] => [authorityToWorkStatement] => [contactPreference] => [EducationLevels_idEducationLevel] => [noOfGcses] => 0 [gcseEnglishGrade] => [gcseMathsGrade] => [fiveOrMoreGcses] => [noOfAlevels] => 0 [ucasPoints] => 0 [studentStatus] => [mobile] => [landline] => [dob] => [penaltyPoints] => ) Quote Link to comment https://forums.phpfreaks.com/topic/148842-mysql-bit-and-php/#findComment-781884 Share on other sites More sharing options...
premiso Posted March 11, 2009 Share Posted March 11, 2009 If you have the field as being "female" why not see if it is null, if it is null then they are male, if it has a value (not null) they are male....? As far as the answer what to check against...I have no clue. I have never used bit, instead I would do a TINYINT(1) that way it can be a 1 or a 0 and boom, problem is solved. I believe bit is binary, and I have never really worked closely with binary information. Quote Link to comment https://forums.phpfreaks.com/topic/148842-mysql-bit-and-php/#findComment-782176 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.