Monkuar Posted February 28, 2012 Share Posted February 28, 2012 $user['gender'] = ($user['gender'] == 1) ? 'Male' : ''; $user['gender'] = ($user['gender'] == 2) ? 'Female' : ''; $user['gender'] = ($user['gender'] == 3) ? 'Hermaphrodite' : ''; I echo out $user['gender'] and it doesn't show the values i put in the terny operator, but if I delete all that, and echo it out it echo's out "1" which is what I have selected, any idea? do i have to use variables other than the mysql $user['gender'] ? Quote Link to comment https://forums.phpfreaks.com/topic/257909-gender-not-working/ Share on other sites More sharing options...
Monkuar Posted February 28, 2012 Author Share Posted February 28, 2012 blah i fixed it if ($user['gender'] == 1){ $g = 'Male'; }else if ($user['gender'] == 2){ $g = 'Female'; }else if ($user['gender'] == 3){ $g = 'Hermaphrodite'; } srry Quote Link to comment https://forums.phpfreaks.com/topic/257909-gender-not-working/#findComment-1321946 Share on other sites More sharing options...
Pikachu2000 Posted February 28, 2012 Share Posted February 28, 2012 Or a more compact way to do it, sans conditionals. $genders = array(1=> 'Male', 'Female', 'Hermaphrodite'); $g = $genders[$user['gender']]; Quote Link to comment https://forums.phpfreaks.com/topic/257909-gender-not-working/#findComment-1321947 Share on other sites More sharing options...
Monkuar Posted February 28, 2012 Author Share Posted February 28, 2012 Or a more compact way to do it, sans conditionals. $genders = array(1=> 'Male', 'Female', 'Hermaphrodite'); $g = $genders[$user['gender']]; WHOA now that is sexy ima use that, lol thank you Quote Link to comment https://forums.phpfreaks.com/topic/257909-gender-not-working/#findComment-1321948 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.