Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Variable problem(again)

    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?

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    try
    PHP Code:
    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
    Last edited by rafiki; 09-04-2007 at 07:28 PM.

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    $all and $ALL are two different variables.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •