Jump to content

Archived

This topic is now archived and is closed to further replies.

JackJack

Fetch Stats

Recommended Posts

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 you

JJ

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[!--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]<?php
switch ($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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.