...

View Full Version : Variable problem(again)



ole90
09-04-2007, 07:20 PM
So i get a value from my database which is either a number or a string.

$database_value = $row['database_value'];

and then i want to compare this value to see whether or not it equals the string "ALL"

so

$all = "ALL";

if(strcmp($database_value, $ALL) == 0) {
echo"Values are equal";
} else {
echo"Values are not equal";
}

But this doesn't seem to be working for me. It always says that database_value does not equal ALL, even though i've checked and double checked that it does contain ALL.

any help?

rafiki
09-04-2007, 07:25 PM
try

if (strcmp($database_value, $all)){
echo "Yes. Values are equal.";
echo '$database_value ==' . $database_value;
echo '$all == ' . $all;
}else{
echo "No. Values are not equal.";
echo '$database_value ==' . $database_value;
echo '$all == ' . $all;
}

//or you could use
if ($database_value == $all){
echo "Yes. Values are equal.";
echo '$database_value ==' . $database_value;
echo '$all == ' . $all;
}else{
echo "No. Values are not equal.";
echo '$database_value ==' . $database_value;
echo '$all == ' . $all;
}
// you choose

p.s I added the echo $database_value == for testing, once you made sure that it is correctly giving out equallity you can remove them

Fumigator
09-04-2007, 07:39 PM
$all and $ALL are two different variables.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum