Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts

    problem with select where

    Hi all

    Any idea why my query is returning the article where priority is set to zero
    when query is to select articles with priority greater than zero?

    Without the AND clause it works, but I need the AND clause so I can't remove it.



    myDatabase setting for 'priority' col
    smallint(11) //values possible from form 0-9

    test field values in database:
    News test test 0


    myQuery in php page:

    $result = $mysqli->query("SELECT `headline`,`title`,`article`,`priority`
    FROM tablename
    WHERE (`priority` > 0)
    AND (`title` IS NOT NULL) OR (`article` IS NOT NULL)



    Debug echo:
    Priority: 1
    Priority: 0 <--this article should not be selected
    Priority: 1
    Priority: 1


    I also tried WHERE (priority >= 1)
    which also didn't work

    I'm puzzled
    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 314 Times in 306 Posts
    The query is matching everything with (`article` IS NOT NULL) being true. or'ing values will return a true if one or both of the values is true - false OR true = true.

    use this logic -
    Code:
    WHERE (`priority` > 0)
    AND ((`title` IS NOT NULL) OR (`article` IS NOT NULL))
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    low tech (02-25-2014)

  • #3
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts
    Hi CFMaBiSmAd

    Ah that looks good. I'll give that a try and post back.

    I'd add a 'thanks' , but I can't see where to add that on the new forum.

    Thanks
    LT
    Last edited by low tech; 02-24-2014 at 01:29 AM.
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #4
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts
    Hi CFMaBiSmAd

    EDIT: Found and clicked THANKS

    Good job

    Your code did the trick nicely.

    Thanks and thanks for the explanation.

    LT
    Last edited by low tech; 02-25-2014 at 05:12 AM.
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.


  •  

    Posting Permissions

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