3 Replies Latest reply on Nov 4, 2008 4:55 AM by meesonator

    PHP IF

    meesonator
      Hi I am having trouble with the || function in an if statement, i have tried this, with no luck.

      <?php if ($totalRows_rsRateCheck == 0 || $colname_rsRateCheck != $colname2_rsRateCheck) {?>

      some stuff

      <?php } else { ?>

      some more stuff

      <?php } ?>

      It always shows the if part whether the conditions are met or not
      Any suggestions would be massively appreciated?
        • 1. Re: PHP IF
          Level 7
          meesonator wrote:
          > Hi I am having trouble with the || function in an if statement,

          It's not a function; it's a conditional operator. I'm not just
          nitpicking. Understanding the correct terminology is vital in learning
          how to use a new technology.

          > <?php if ($totalRows_rsRateCheck == 0 || $colname_rsRateCheck !=
          > $colname2_rsRateCheck) {?>
          >
          > some stuff
          >
          > <?php } else { ?>
          >
          > some more stuff
          >
          > <?php } ?>
          >
          > It always shows the if part whether the conditions are met or not

          If it always shows the if part, the conditions are being met. What it
          means is that either you have misunderstood the meaning of your
          conditional statement, or that the variables don't hold the values that
          you expect. Let's deal with each one in turn.

          1. Your conditional statement means this:

          "If $totalRows_rsRateCheck is zero OR
          if $colname_rsRateCheck and $colname2_rsRateCheck are different"

          If either condition is true, the if part of your code will be executed.

          2. If that's what you want the conditional statement to check, you next
          need to find out what the variables contain. That will help you
          understand why the code isn't working the way you expect. Use echo to
          display the values:

          echo '$totalRows_rsRateCheck: ' . $totalRows_rsRateCheck;
          echo '<br />$colname_rsRateCheck: ' . $colname_rsRateCheck;
          echo '<br />$colname2_rsRateCheck: ' . $colname2_rsRateCheck;

          Note that I have deliberately used single quotes so that you see the
          name of the variable as well as its value. If you use double quotes, PHP
          will display the value, rather than the variable name.

          --
          David Powers, Adobe Community Expert
          Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
          Author, "PHP Solutions" (friends of ED)
          http://foundationphp.com/
          • 2. Re: PHP IF
            Level 7
            It should work. But try this -

            <?php if ($totalRows_rsRateCheck == 0 || trim($colname_rsRateCheck) !=
            trim($colname2_rsRateCheck)) {?>
            <?php echo $colname_rsRateCheck . " -- " . $colname2_rsRateCheck; ?>

            (that'll give you a visual of the comparison values)

            --
            Murray --- ICQ 71997575
            Adobe Community Expert
            (If you *MUST* email me, don't LAUGH when you do so!)
            ==================
            http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
            http://www.dwfaq.com - DW FAQs, Tutorials & Resources
            ==================


            "meesonator" <webforumsuser@macromedia.com> wrote in message
            news:gepa5q$ia9$1@forums.macromedia.com...
            > Hi I am having trouble with the || function in an if statement, i have
            > tried
            > this, with no luck.
            >
            > <?php if ($totalRows_rsRateCheck == 0 || $colname_rsRateCheck !=
            > $colname2_rsRateCheck) {?>
            >
            > some stuff
            >
            > <?php } else { ?>
            >
            > some more stuff
            >
            > <?php } ?>
            >
            > It always shows the if part whether the conditions are met or not
            > Any suggestions would be massively appreciated?
            >

            • 3. Re: PHP IF
              meesonator Level 1
              OK i have been a moron i wrote
              <?php if ($totalRows_rsRateCheck == 0 || $colname_rsRateCheck != $colname2_rsRateCheck) {?>

              thinking that if condition 1 was false, or condition 2 was false then not to display the rest of the code.
              Stupid i know, i have replaced || with &&

              <?php if ($totalRows_rsRateCheck == 0 && $colname_rsRateCheck != $colname2_rsRateCheck) {?>

              Cheers David, and Murry, it seems so obvious when you see it written out. Much appreiciated.