我有枚举字段制造商
`manufacturer` ENUM('Manufacturer1','Manufacturer2','Manufacturer3','Manufacturer4') NOT NULL
我有一个包含多个制造商值的数组。请写出可以选择每一行的查询,比如说,例如,manufacturer1或manufacturer3?
我可以这样写:
SELECT FROM table_name WHERE manufacturer=manufacturer1 OR manufacturer=manufacturer3;
但我正在寻找更短的版本,如:
SELECT FROM table_name WHERE manufacturer=$myArrayOfManufaturers;
我获得了制造商表格清单的可能值,因此制造商的数量可以根据用户的选择而改变。
我的网站是使用CodeIgniter构建的,所以我尝试了
$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)
}
但无法理解如何将第一个设置为where。
答案 0 :(得分:3)
您可以使用IN查询,如
SELECT FROM table_name WHERE manufacturer IN ('Manufacturer1','Manufacturer2')