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
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    IF Statement Help

    morning ..

    struggiling with some if statements here... don't seem to be doing as they should, think maybe I'm overlooking something you guys may spot ...

    In a cookie I have myid .. this is always a number I can display the myid on my page either just by typing $myid or by using the full $HTTP_COOKIE_VARS['myid']. Either way that works fine, and it always shows the correct myid.
    The problem I have is my if statements do not take notice of the cookie variable .. I have ...
    PHP Code:
    if($status==AND $cid=='$myid'){ //here I just include a file } 
    if($status==AND $cid=='$myid'){ //here I have a html table with some text in }
    if($status==3//here I have another include } 
    Now this is very strange .. the first if statement works fine, it only includes the file if status is 2 and the cid (this comes from a DB) is the same as myid, the cookie var.. that works great.. however the second if statement.. ALWAYS prints the table when status is 3... no matter what the cid and myid is, it will always print.. as if it is ignoring the AND.

    The third if statement works fine too.
    I have tried alterations of the if statements .. for example ...
    PHP Code:
    if($status==AND $cid==$myid){ //here I just include a file } 
    if($status==AND $cid==$myid//here I have a html table with some text in }
    if($status==3//here I have another include } 
    and ...
    PHP Code:
    if($status=='2' AND $cid==$HTTP_COOKIE_VARS['myid']){ //here I just include a file } 
    if($status=='3' AND $cid==$HTTP_COOKIE_VARS['myid']){ //here I have a html table with some text in }
    if($status=='3'//here I have another include } 
    . and it still does not work.. it never errors though.
    Its very stange that the first if statement works and the second does not.

    If anyone can see what I have done wrong, id be very greatful to hear

    Thanks kindly,
    Sir P

  • #2
    New Coder
    Join Date
    Feb 2006
    Location
    Germany
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I do not exactly know what the problem is and only can suggest to echo both values for debugging and see.
    However I have a simple solution to your problem: elseif !

    PHP Code:
    if($status==AND $cid=='$myid'){ //here I just include a file 
    } elseif($status==AND $cid=='$myid'){ //here I have a html table with some text in }
    if($status==3//here I have another include } 
    I hope that helps,

    - Felix

    Edit: I realized that this only works as long as $status does not get changed by the file you are including.

    Anyway I would just suggest to place a echo before the if-statement;
    Chances are that the problem doesn't lie within the IF structure.

    The only thing I could think of ( but really is more than unlikely ) is the ' ' when comparing; you could try to just use $cid == $myid

    Eh you tried that already. Sorry I'm slow. Anyway I guess all I can recommend is echoing both values before the IF statement.

    Another thing you could try:
    PHP Code:
    if( ($status==2) && ($cid==$myid)){ //here I just include a file } 
    if(($status==3) && ($cid==$myid)){ //here I have a html table with some text in }
    if($status==3){ //here I have another include } 
    Last edited by Bio2hazard; 02-14-2006 at 10:43 AM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Hey Bio...

    Thanks your for your time in replying.
    I tried the elseif but had same problem so started echo'ing out as you said ...

    The problem was ... previously on my page I had ..
    PHP Code:
    if($status=3){ stuff 
    ... so the if statement was actually setting status to 3, no matter what. I have changed that to '==' instead of just '=' and still had slight problem, but as you said.. remove the ' ' ... so $cid=='$myid' became $cid==$myid.

    And it all works now... urg that missing = gave me ALL THAT trouble haha.

    Thank you kindly for you time Bio
    P


  •  

    Posting Permissions

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