By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,724 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,724 IT Pros & Developers. It's quick & easy.

Strange IF behaviour

P: n/a
$nst is definitely set to 4, as the echo $nst; gives 4.

However, with:

echo $nst;
echo "<br>";
if ($nst= 1) {
$fulls = "Full status for 1";
} elseif ($nst = 2) {
$fulls = "Full status for 2";
} elseif ($nst= 4) {
$fulls = "Full status for 4";
}

echo "Status: " . $fulls;

$fulls is *always* the first one "Full status for 1", even when $nst is 4.

What am I doing wrong?

Thanks,

Ben
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
go****@bwgames.net (BWGames) wrote:
$nst is definitely set to 4, as the echo $nst; gives 4.

However, with:

echo $nst;
echo "<br>";
if ($nst= 1) {
$fulls = "Full status for 1";
} elseif ($nst = 2) {
$fulls = "Full status for 2";
} elseif ($nst= 4) {
$fulls = "Full status for 4";
}

echo "Status: " . $fulls;

$fulls is *always* the first one "Full status for 1", even when $nst
is 4.


You are assigning the values, not comparing ;)

if ($nst == 1) {

HTH;
JOn
Jul 17 '05 #2

P: n/a
Jon Kraft wrote:
go****@bwgames.net (BWGames) wrote:
$nst is definitely set to 4, as the echo $nst; gives 4.

However, with:

echo $nst;
echo "<br>";
if ($nst= 1) {
$fulls = "Full status for 1";
} elseif ($nst = 2) {
$fulls = "Full status for 2";
} elseif ($nst= 4) {
$fulls = "Full status for 4";
}

echo "Status: " . $fulls;

$fulls is *always* the first one "Full status for 1", even when $nst
is 4.


You are assigning the values, not comparing ;)

if ($nst == 1) {


Also, this is better solved by switch:

switch($nst) {
case 1 :
$fulls = "Full status for 1";
break;
case 2 :
$fulls = "Full status for 2";
break;
case 4 :
$fulls = "Full status for 4";
break;
}
--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.