1

when building the query in mySQL, How do I fetch the result with multiple values

Example code:

if (strtolower($_REQUEST['shirt_color']) == 'showall' && (isset($_REQUEST['shirt_type']))
        {
            $params[] = array('field' => 'color_type',
                       'operator' => '=',
                      'value' => 'black'
                              );
        }

The above pice of code works fine and gets the correct results, However I want to search for two different colors:

I tried putting --- 'value' => "'black' OR 'white'" but it doesnt work.

3
  • 1
    You should show us how these params are processed by script generating sql query. One thing that comes to my mind is setting an operator to IN and value to ('black', 'white') Commented Aug 5, 2015 at 6:03
  • Please display the raw query sent to the database Commented Aug 5, 2015 at 6:11
  • show us your query... Commented Aug 5, 2015 at 6:12

2 Answers 2

2

Try the IN operator. Something like that shall be your resulting query:

SELECT * FROM tshirts WHERE color IN ('black','white');

If you provide us with the code you have to generate the query string, we could help you with adapting it to the IN operator.

Sign up to request clarification or add additional context in comments.

Comments

1

Try using something like

Select * from tshirts where color = 'black' OR color = 'white'

1 Comment

Should there be only unique key for dictionary, I believe?

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.