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
    New Coder
    Join Date
    Jul 2009
    Location
    New Jersey
    Posts
    32
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Checking two statments

    Hey everyone, have a very simple issue that for some reason I can't seem to come up with the correct if statement for.

    I have a game, when a user is placed on a list they will not be able to use some of the functions in the game, one of them being the Hospital.

    I am trying to use this code, the $user comes from a table called users, the $row[hitUserid], comes from another table called list.

    What I would like it to show is if the user is on the list then they can not heal right now.. If they are not on the list then they can heal or if their health is full it says the else command at the bottom..

    Any suggestions to why it's not working?

    Thanks!

    Code:
    $pirate = Pirate::getById($user);
    
    if ($user == $row[hitUserid]) {
    echo '<div id="reply" style="background-color:#ffffff; width:500px; Height:25px; padding:2px; border: solid #cccccc 3px;">can not heal right now</div>';
    }
    else if ($pirate->health < $pirate->maxhealth) {
    
    echo '<div id="reply" style="background-color:#ffffff; width:500px; Height:25px; padding:2px; border: solid #cccccc 3px;"><a Onclick="hospital(\'reply\'); return false;">Heal your character for $';
    $valore = ($pirate->maxhealth - $pirate->health) * 5 * $pirate->level;
    echo $valore; echo '</a></div>'; 
    
    
    } else { echo '<P class="bigWhiteP">You are now at full health!</P>';}

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I'm not sure if having single quotes on the variable name makes a difference or not ...

    $row['hitUserid']

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    mlseim, PHP still works with the incorrect syntax, but it's accidental and unsupported behavior. It's on this manual page under the section "Why is $foo[bar] wrong?".

    To the OP, which case is actually failing to work like you expect? Your post seems ambiguous.
    Are you a Help Vampire?


  •  

    Posting Permissions

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