我想知道如何检查表(经理)中是否存在值,然后根据该表中是否存在值添加“是”或“否”字符串。
$this->db->select('employees.first_name, employees.last_name, departments.department_name, departments.department_numb, titles.title');
$this->db->from('employees');
$this->db->where('first_name', $firstname);
$this->db->where('last_name', $lastname);
$this->db->join('department_manager', 'department_manager.emp_numb = employees.emp_numb', 'inner');
$this->db->join('departments', 'departments.department_numb = department_manager.department_numb', 'inner');
$this->db->join('titles', 'titles.emp_numb = employees.emp_numb', 'inner');
$this->db->where('department_name', $dept);
$this->db->where('title', $jobtitle);
$result = $this->db->get();
$data = array();
foreach($result->result() as $row)
{
$entry = array();
$entry['firstname'] = $row->first_name;
$entry['lastname'] = $row->last_name;
$entry['jobtitle'] = $row->title;
$entry['dept'] = $row->department_name;
$entry['deptid'] = $row->department_number;
//$entry['ismanager'] =
$data[] = $entry;
}
return $data;
我想检查员工是否存在于'department_manager'
由员工编号连接的表中。因此,如果表“department_manager”中不存在该员工编号,那么我想在数组索引中插入$entry[ismanager']
一个表示“否”的字符串,如果员工编号存在于表“department_manager”中,那么我想$entry['ismanager']
保留字符串“是”。
但我对如何检查该员工是否在该表中感到困惑。我是在活动记录查询中还是在 foreach 循环中执行此操作?如果它是在 foreach 循环中完成的,那么在查询完成时如何进行比较?