mysql-zend框架中使用多个值和多个字段进行搜索

63lcw9qa  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(400)

在这里,我有三个多选组合框,即department、designation和location,用户可以在每个字段中选择多个值。我执行一个 OR 操作以显示至少属于其中一个字段的员工的姓名。
如果我只选择一个部门名称、指定名称和位置,这个方法很有效。如果我选择了一个以上的值,它就不起作用了。我得去兜圈子 WHERE 基于所选计数的部门状况、名称和位置。
我怎么能只在这里循环这个条件,使它变成 select 'emp_id' from emp_personal' where Department_Id='1' or Department_Id='7' or Designation_Id='6'.... ```
public function listEmployees($searchArray=null, $logEmpId=null, $formName=null)
{

$department = $searchArray['Department'];
$designation= $searchArray['Designation'];
$location=$searchArray['Location'];

  $conditions=$this->_db->quoteInto('Department_Id =?', $department);  
  $conditions .= $this->_db->quoteInto('or Designation_Id = ?', $designation);
  $conditions .= $this->_db->quoteInto('or Location_Id = ?', $location);
  $qryEmployees= $this->_db->select()->from(array('En'=>$this->_ehrTables->empJob), array('En.Employee_Id'))->where($conditions)

 ->joinInner(array('E'=>$this->_ehrTables->empPersonal), 'E.Employee_Id = En.Employee_Id', array('Employee_Name'=>new Zend_Db_Expr("CONCAT(E.Emp_First_Name, ' ', E.Emp_Last_Name)")));

$result = $this->_db->fetchAll($qryEmployees);
return $result;

}

jljoyd4f

jljoyd4f1#

尝试使用select in(值1,值2,…)

相关问题