Professional Web Applications Themes

whats wrong with this statment? - PHP Development

Hi all whats wrong with this? if ( (strtolower($myrow[status]) != 'n') || (strtolower($myrow[status]) != 'u') ) { ........ } I'm trying to say if $myrow[status]) if not 'n' or 'u' then do X but it's just not playing ball here? I have tried putting in brackets, taking them out, moving them about and all sorts, just can't get it to work Brian...

  1. #1

    Default whats wrong with this statment?

    Hi all

    whats wrong with this?

    if ( (strtolower($myrow[status]) != 'n') || (strtolower($myrow[status]) !=
    'u') ) {
    ........
    }

    I'm trying to say if $myrow[status]) if not 'n' or 'u' then do X but it's
    just not
    playing ball here? I have tried putting in brackets, taking them out, moving
    them about and all sorts, just can't get it to work



    Brian


    Brian Guest

  2. #2

    Default Re: whats wrong with this statment?

    Let's say $myrow[status] = "n". The if statement is true because it is not
    "u". Let's say it is "u". The if statement is true because it is not "n".
    Let's say it is "x". The if statement is true because it is not "n".

    I would do it this way :
    $status = strtolower($myrow[status])
    if (&status = "n" || & status = "u")
    {
    // do yes stuff (nothing in this case)
    }
    else
    {
    // do your not n or u stuff
    }

    HTH,
    Lee


    "Brian" <com> wrote in message
    news:C%ple.24$ntli.net... 


    Lee Guest

  3. #3

    Default Re: whats wrong with this statment?

    Brian spilled the following:
     

    For starters, the line is too long and unnecessarily re-evaluating the
    function.

    It's doing exactly what you tell it - you have a semantic error in your
    program. Try making it a bit simpler and it might be clearer:

    $ch = strtolower($myrow[status]);
    if ( ($ch!='n') || ($ch!='u') ) { ...

    At least one of the two expressions will always be true (since $ch cannot be
    'u' and 'n' at the same time)

    I suspect you really mean not 'n' *AND* not 'u'

    HTH

    C.
    Colin Guest

  4. #4

    Default Re: whats wrong with this statment?

    >> Hi all 
    >
    > For starters, the line is too long and unnecessarily re-evaluating the
    > function.
    >
    > It's doing exactly what you tell it - you have a semantic error in your
    > program. Try making it a bit simpler and it might be clearer:
    >
    > $ch = strtolower($myrow[status]);
    > if ( ($ch!='n') || ($ch!='u') ) { ...
    >
    > At least one of the two expressions will always be true (since $ch cannot
    > be
    > 'u' and 'n' at the same time)
    >
    > I suspect you really mean not 'n' *AND* not 'u'
    >
    > HTH
    >
    > C.[/ref]

    WHAT THE HELL AM I ON???

    Thanks guys, I have gone brain dead on this project, I need a break from it
    as I am making silly mistakes that I should know better on, like AND instead
    of
    OR
    That's what happens when you client changes things haft way though writing
    the code, you end up with a 1 brain dead programmer and code that looks and
    acts S**t !



    Thanks guys

    Brain dead Brian


    Brian


    Brian Guest

  5. #5

    Default Re: whats wrong with this statment?



    --
    Welcome to Usenet! Please leave tolerance, understanding
    and intelligence at the door. They aren't welcome here.
    eternal piste erection miuku gmail piste com
    "Lee David" <net> wrote in message
    news:com... 

    Did you mean
    if ($status == "n" || $status == "u")

    If-statements are fun.
    if( '=' != '==' )
    echo "monkeys don't fly out of my butt";
    else
    echo "monkeys fly out of my butt";


    Kimmo Guest

  6. #6

    Default Re: whats wrong with this statment?

    Yep. Still learning the syntax of PHP. I hate "and"ing negatives so I just
    create the positive and else to it or I use a switch/case statement. As I
    write in several languages (PL/1, COBOL, PAL, Pascal, Basic, VB, javascript,
    java, DIS, JCL, clist, and a few others) and as I'm older than dirt, I get
    confused on the syntax sometimes. I wanted to move from ASP to PHP so I'm
    learning that now.

    Lee


    Lee Guest

Similar Threads

  1. whats wrong with my sql?
    By loofa in forum Coldfusion Database Access
    Replies: 3
    Last Post: July 25th, 08:47 AM
  2. whats wrong here?
    By Bionicegg in forum Macromedia Flash Sitedesign
    Replies: 2
    Last Post: June 13th, 10:28 PM
  3. Anyone know whats wrong with this?
    By Mike M in forum ASP Database
    Replies: 5
    Last Post: February 17th, 11:56 PM
  4. [PHP] Whats wrong?
    By Ryan A in forum PHP Development
    Replies: 0
    Last Post: September 13th, 01:07 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139