Results 1 to 8 of 8

Thread: Problem IF Statements

  1. #1
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Problem IF Statements

    I have 2 IF statements and they dont seem to work as they are told.

    PHP Code:
    <?
    if ($myrow["svc"] = "%RMA-%") {
    echo 
    '<div class="tmodule">';
    echo 
    '<h3>Reason for return:</h3>';
    echo 
    '<div>';
    echo 
    '',$myrowr["reason"],'';
    echo 
    '</div>';
    echo 
    '</div>';
    echo 
    '<div class="tmodule">';
    echo 
    '<h3>Special Instructions or Notes:</h3>';
    echo 
    '<div>';
    echo 
    '',$myrowr["notes"],'';
    echo 
    '</div>';
    echo 
    '</div>';
    }
    else {}
    ?>
    <?
    if ($myrow["svc"] = "%T-%") {
    echo 
    '<div class="tmodule">';
    echo 
    '<h3>Special Instructions or Notes:</h3>';
    echo 
    '<div>';
    echo 
    '',$myrowt["notes"],'';
    echo 
    '</div>';
    echo 
    '</div>';
    }
    else {}
    ?>
    When an RMA record is selected it should only show the RMA statement and not the trade and same with a trade record. But when i selected an RMA record the Trade statement shows up also same with a trade record the rma show up also. No data is in the divs but the div box's show up.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    = is an assignment operator, and will always return the value on its right-hand side. == is a comparison operator, and returns either true or false depending on whether or not the left- and right-hand operands are equal. Do not confuse them. If you are prone to doing so, put the absolute value (where possible) on the left-hand side, so that PHP throws an "operation not supported" error rather than continuing to execute your code in a manner you didn't intend.

    echo '',$myrowt["notes"],'';
    What's the point of those empty quotes? There's no need for them to be there.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    Habbit lol and replaced = with == and now nothing shows up.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Because, I daresay, neither of your conditions were met.

    Oh, the empty else clauses are rather pointless too.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    I know the conditions should be met theres tons of RMA and T records in there. I just want it to check and see of the SVC is an RMA or a T and display the correct DIV's

    PHP Code:
    <?
    if ($myrow["svc"] == "RMA-%") {
    echo 
    '<div class="tmodule">';
    echo 
    '<h3>Reason for return:</h3>';
    echo 
    '<div>';
    echo 
    $myrowr["reason"];
    echo 
    '</div>';
    echo 
    '</div>';
    echo 
    '<div class="tmodule">';
    echo 
    '<h3>Special Instructions or Notes:</h3>';
    echo 
    '<div>';
    echo 
    $myrowr["notes"];
    echo 
    '</div>';
    echo 
    '</div>';
    }
    ?>
    <?
    if ($myrow["svc"] == "T-%") {
    echo 
    '<div class="tmodule">';
    echo 
    '<h3>Special Instructions or Notes:</h3>';
    echo 
    '<div>';
    echo 
    $myrowt["notes"];
    echo 
    '</div>';
    echo 
    '</div>';
    }
    ?>

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by NXArmada
    if ($myrow["svc"] = "%RMA-%") {
    To continue what Twey wrote, you seem to be trying to apply pattern matching in SQL to PHP, which doesn't work.

    If you want to check if a substring exists within some other string, use the strpos function:

    Code:
    if (strpos($myrow['svc'], 'RMA-') != -1) {
      /* 'RMA-' exists somewhere within the string. */
    }
    If you want to check that the string starts with a particular substring, you can use the following function.

    Code:
    function beginsWith($string, $prefix) {
      return $prefix === substr($string, 0, strlen($prefix));
    }
    
    if (beginsWith($myrow['svc'], 'RMA-')) {
      /* ... */
    }
    Mike

  7. #7
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    the strpos bring me back to my original problem

    and the beginsWith give me function errors

  8. #8
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    I got the Begins with to work stupid me lol thanks for the awsome help guys.

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
  •