Announcement

Collapse
No announcement yet.

PHP - using the "<" less than symbol will not parse

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    PHP - using the "<" less than symbol will not parse

    Hi
    Is it me? Consider something noddy like this in PHP

    Lets test if a number falls between a particular range:

    $weight = 15;
    $a = 10;
    $b = 20;
    If ($weight > $a AND $weight < $b)
    {
    echo "Success"
    }

    In the editor, text after the "<" symbol goes red and the function does not work. From all I have read on this, it should work. If I change the "<" to a "=" or a ">" it loses the red and appears to parse.
    Does sellerdeck have an issue with using the "<" in PHP and if so why and what is the workaround.

    Any ideas ?

    #2
    Use && instead of AND. Also consider using brackets to make it clear what is being done.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      The colouring is just SD getting confused. It thinks it's parsing HTML not PHP. It's a display issue only.
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        Hi there - many thanks for the reply. I have been at this all day and have tried every combination of &&, AND and brackets I can think of - nothing so far has worked. I also thought it was just a colouring issue, except that the "success" does not display.

        Comment


          #5
          Tried all these
          If ($weight > $a AND $weight < $b)
          If ($weight > $a && $weight < $b)
          If (($weight > $a) AND ($weight < $b))
          If (($weight > $a) && ($weight < $b))

          Comment


            #6
            You also had a missing ; at the end of the echo statement. This works correctly:
            Code:
            <actinic:block php="true">
            $weight = 15;
            $a = 10;
            $b = 20;
            if ( ($weight > $a) && ($weight < $b) )
              {
              echo "Success";
              }
            </actinic:block>
            And includes helper parentheses for those who don't understand operator precedence.
            It is also a good idea to use lower case for PHP keywords. Use if instead of If.
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              Hi many thanks for that - I think the problem I am having is because I am actually trying to use the Sellerdeck field "shippingweight".
              Consider this:

              $x = "shippingweight"; (this is the inserted sellerdeck variable)

              If I display $x I get 0.7 because that is the value I have in the "Weight in kg" field for the product. OK that is what I expected.

              The problem is that $x is a text field, so when I do the compare operation in the posts above it does not work.
              If I do (float)$x to convert to a floating point number, the result is 0.
              I have tried all sorts of things to get $x to be a numeric field with 0.7 as it's contents with no luck.

              Any ideas ?

              Comment


                #8
                ShippingWeight is always numeric so putting it inside quotes is unnecessary. Demo code that works here:
                Code:
                <actinic:block php="true">
                $x = <actinic:variable name="ShippingWeight" selectable="false" />;  // treat as numeric / selectable="false" prevents errors in the Design Preview
                echo ($x + 1); // demonstrate that we can do arithmetic with it
                </actinic:block>
                Best display the entire lump of PHP you are using as the problem may not be in the isolated snippets you post.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  Great - I could not get it to work at all without the quotes, hence putting them in. But the selectable="false" has solved it. It does not put that in by default and I do not know how I would know to put it in. Anyway, it works now. Many thanks.

                  Comment

                  Working...
                  X