2

I have enum field Manufacturer

`manufacturer` ENUM('Manufacturer1','Manufacturer2','Manufacturer3','Manufacturer4') NOT NULL 

and I have a array containing multiple manufacturer values. Ho to write query that would select every row that has, lets say for example, manufacturer1 or manufacturer3?

I could write it like this:

SELECT FROM table_name WHERE manufacturer=manufacturer1 OR manufacturer=manufacturer3;

but I am looking for shorter version like:

SELECT FROM table_name WHERE manufacturer=$myArrayOfManufaturers;

I get possible values of manufacturers form checklist so the number of manufacturers can change depending from user choice.

My site is built using CodeIgniter so I tried

    $query = $this->db->get_where('products', array('manufacturer' => $data['manufacturers']));
and using forech loop
foreach ($data['manufaturers'] as $man) {
            $this->db->or_where('manufacturer'=$man)
            }

but can not understand how to set first one as where.

1 Answer 1

5

You can use IN query like

SELECT FROM table_name WHERE manufacturer IN ('Manufacturer1','Manufacturer2')
Sign up to request clarification or add additional context in comments.

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.