JackJack Posted April 6, 2006 Share Posted April 6, 2006 It always selects the last if option.[code]<?include("../inc/headers.inc.php"); $lmao = mysql_query("SELECT * FROM test WHERE id=1"); while ($test = mysql_fetch_array($lmao)) {$hungry = $test[current_hunger];if ($hungry = '0'){$hunger = 'Starving';}if ($hungry = '1'){$hunger = 'Famished';}if ($hungry = '2'){$hunger = 'Hungry';}if ($hungry = '3'){$hunger = 'Unsatisfied';}if ($hungry = '4'){$hunger = 'Unsatisfied';}if ($hungry = '5'){$hunger = 'Satisfied';}if ($hungry = '6'){$hunger = 'Full';}if ($hungry = '7'){$hunger = 'Bloated';}echo "Hunger - $hunger";echo "<br>$hungry";}?>[/code] Thank youJJ Quote Link to comment https://forums.phpfreaks.com/topic/6741-fetch-stats/ Share on other sites More sharing options...
wildteen88 Posted April 6, 2006 Share Posted April 6, 2006 You are using the assignment operater (=) rathar than the comparison operator (==). Also chnage your if statments to an if/elseif statment like so:[code]if ($hungry == '0') { $hunger = 'Starving';}elseif ($hungry == '1') { $hunger = 'Famished';}elseif ($hungry == '2') { $hunger = 'Hungry';}elseif ($hungry == '3') { $hunger = 'Unsatisfied';}elseif ($hungry == '4') { $hunger = 'Unsatisfied';}elseif ($hungry == '5') { $hunger = 'Satisfied';}elseif ($hungry = '6') { $hunger = 'Full';}elseif ($hungry = '7') { $hunger = 'Bloated';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6741-fetch-stats/#findComment-24515 Share on other sites More sharing options...
underparnv Posted April 6, 2006 Share Posted April 6, 2006 [!--quoteo(post=362282:date=Apr 6 2006, 10:14 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 6 2006, 10:14 AM) [snapback]362282[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]if ($hungry == '0') { $hunger = 'Starving';}elseif ($hungry == '1') { $hunger = 'Famished';}elseif ($hungry == '2') { $hunger = 'Hungry';}elseif ($hungry == '3') { $hunger = 'Unsatisfied';}elseif ($hungry == '4') { $hunger = 'Unsatisfied';}elseif ($hungry == '5') { $hunger = 'Satisfied';}elseif ($hungry = '6') { $hunger = 'Full';}elseif ($hungry = '7') { $hunger = 'Bloated';}[/code][/quote]I personally prefer the switch statement:[code]<?phpswitch ($hungry) { case 0: $hunger = "Starving"; break; case 1: $hunger = "Famished"; break; case 2: $hunger = "Hungry"; break; case 3: case 4: $hunger = "Unsatisfied"; break; case 5: $hunger = "Satisfied"; break; case 6: $hunger = "Full"; break; case 7: $hunger = "Bloated"; break; default: $hunger = "Something other than 0-7...";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6741-fetch-stats/#findComment-24589 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.