syed_h
syed_h

Reputation: 120

MySQL 'or' statement with multiple values

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.

Upvotes: 1

Views: 72

Answers (2)

Elyor
Elyor

Reputation: 5532

Try using something like

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

Upvotes: 1

Zim84
Zim84

Reputation: 3497

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.

Upvotes: 2

Related Questions