Multiple OR AND select statement. Please help me out!

Discussion in 'PHP' started by lslars31, Aug 15, 2007.

  1. #1
    I have this:

     $query = "SELECT * FROM businesses WHERE active='1' AND zipa='$_GET[search]' OR extrazips LIKE '%$_GET[search]%' ORDER BY id DESC LIMIT $offset, $rowsPerPage";
    
    PHP:
    Except that doesn't work....

    Is there a way to block them off to let mysql know how to evaluate it?

    ex:

     $query = "SELECT * FROM businesses WHERE active='1' AND (zipa='$_GET[search]' OR extrazips LIKE '%$_GET[search]%') ORDER BY id DESC LIMIT $offset, $rowsPerPage";
    
    PHP:
     
    lslars31, Aug 15, 2007 IP
  2. Riku

    Riku Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could remove the "active='1'" clause, and remove partenthesis. Then while looping you could then have an if statement: "if ($row['active'] == 1) {"
     
    Riku, Aug 15, 2007 IP
  3. lslars31

    lslars31 Peon

    Messages:
    260
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    DUH! thanks that should work... however... when looping through a bunch of rows that could be a problem. Any other ideas?
     
    lslars31, Aug 15, 2007 IP
  4. lslars31

    lslars31 Peon

    Messages:
    260
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    figured it out! thanks for the help. Topic can be closed/deleted
     
    lslars31, Aug 15, 2007 IP