0

I need to do a select that select only the abv = "yes" and other filters,like:

SELECT *
FROM `business`
WHERE `category` LIKE ('$_GET[search]%')
OR `location` LIKE ('$_GET[search]%')
OR `name` LIKE ('$_GET[search]%')
OR `address` LIKE ('$_GET[search]%')
AND `apv`='yes'

This is not working, if I put it all AND does not return anything, on the other hand if I put OR returns including the apv is different from "yes"

I need to select it:

SELECT *
FROM `business`
WHERE `category` LIKE ('$_GET[search]%')
OR `location` LIKE ('$_GET[search]%')
OR `name` LIKE ('$_GET[search]%')
OR `address` LIKE ('$_GET[search]%')

But only with apv="yes"

1
  • 3
    Not directly related to the question but please be careful about SQL injection vulnerabilities. The dynamic SQL in this question has a big security hole. Commented Sep 30, 2009 at 21:41

2 Answers 2

2

Try

    SELECT *
FROM `business`
WHERE (
 `category` LIKE ('$_GET[search]%')
 OR `location` LIKE ('$_GET[search]%')
 OR `name` LIKE ('$_GET[search]%')
 OR `address` LIKE ('$_GET[search]%')
)
AND `apv`='yes'
Sign up to request clarification or add additional context in comments.

Comments

2

Did you try putting parens around the or clauses?

SELECT *
    FROM `business`
    WHERE (
    `category` LIKE ('$_GET[search]%')
    OR `location` LIKE ('$_GET[search]%')
    OR `name` LIKE ('$_GET[search]%')
    OR `address` LIKE ('$_GET[search]%')
    )
    AND `apv`='yes'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.