SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot NuWeb's Avatar
    Join Date
    Aug 2005
    Location
    UK
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if(($order !== "order") OR ($order !== "order2")){

    The Code:
    PHP Code:
    $order "stat_votes_up";
        echo 
    $order.'<br>';
        if((
    $order !== "stat_today_hits") OR ($order !== "stat_total_hits") OR ($order !== "stat_votes_up") OR ($order !== "item_id")){$order "stat_total_hits";}
        echo 
    $order

    Or This Code

    PHP Code:
    $order "stat_votes_up";
        echo 
    $order;
        if(
    $order !== ("stat_today_hits" OR "stat_total_hits" OR "stat_votes_up" OR "item_id")){$order "stat_total_hits";}
        echo 
    $order
    Output:
    Code:
    stat_votes_up
    stat_total_hits
    As you can see, the If is not working. Im doing something wrong? but not sure what.

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Rather than all those conditional statements, you could use something like the following...
    PHP Code:
    <?php
    $aOptions 
    = array(
        
    'page_one',
        
    'page_two',
        
    'page_six',
        
    'page_ten'
    );
    $sOrder in_array($sOrder$aOptions) ? $sOrder 'page_default' ;
    ?>
    Your first code sample is correct though, the second is not.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Zealot NuWeb's Avatar
    Join Date
    Aug 2005
    Location
    UK
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked a treat!
    Likely more efficient as well, wrote down in_array for future.
    TY!

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Heh, don't know about that!

    Glad to have helped, feel free to 'bing' if you get stuck.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,910
    Mentioned
    96 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $order "stat_votes_up";
        echo 
    $order.'<br>';
        if((!
    $order == "stat_today_hits") OR (!$order == "stat_total_hits") OR (!$order == "stat_votes_up") OR (!$order == "item_id")){$order "stat_total_hits";}
        echo 
    $order
    The !== is not a valid operator
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    The !== is not a valid operator
    It's a valid Comparison Operator, but the OP doesn't use it in the code sample you quote though.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,608
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    The problem with the OPs original code is that since a field can't have multiple values at the same time all but one of the not equals will be true regardless of what vcalue the field has and since with OR statements any one being true satisfies the condition the test will always return true. To get the intended result with the minimum of changes from the original code the OR should all be replaced with AND.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •