How to make this SQL query work?

Discussion in 'PHP' started by adamjblakey, Sep 6, 2007.

  1. #1
    Hi,

    I can't see how i can get this to work.

    $select = "SELECT * FROM loads WHERE deliverydate > DATE_ADD(NOW(),INTERVAL -120 HOUR)+0 AND urgency = 'urgent' OR  urgency = 'N/A' ORDER BY 'loadready'";
    Code (markup):
    It won't display anything that equals N/A just urgent.

    Cheers,
    Adam
     
    adamjblakey, Sep 6, 2007 IP
  2. ssanders82

    ssanders82 Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    1.) What's with the "+0" after your DATE_ADD?

    2.) Put parenthesis around "urgency = 'urgent' OR urgency = 'N/A'". Anytime you have AND's and OR's all in a SQL statement, be careful about what your OR is comparing.
     
    ssanders82, Sep 6, 2007 IP
  3. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #3
    It probably wont solve the issue but instead of using

    urgency = 'urgent' OR urgency = 'N/A'
    Code (markup):
    you could use

    urgency IN ('urgent','N/A')
    Code (markup):
    You may get a better response in the database forum

    Brew
     
    Brewster, Sep 6, 2007 IP
  4. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Thanks a lot.

    This "urgency IN ('urgent','N/A')" is working fine.
     
    adamjblakey, Sep 7, 2007 IP