我有两个数组
Array
(
[0] => stdClass Object
(
[id] => 14
[employee_id] => ST0011
[emp_name] => Munish Sharma
[gender] =>
[marital_status] =>
[address] =>
[postal_code] =>
[home_phone] =>
[mobile_phone] =>
[work_email] =>
[private_email] =>
[joined_date] => 1970-01-01 00:00:00
[emp_salary] => 0
[confirmation_date] => 0000-00-00 00:00:00
[department] => HRM
[f_name] => fname
[dob] => 1970-01-01
[c_address] =>
[domainName] =>
[emp_status] => active
)
[1] => stdClass Object
(
[id] => 12
[employee_id] => ST001dasd
[emp_name] => Rakesh Negi
[gender] =>
[marital_status] =>
[address] =>
[postal_code] =>
[home_phone] =>
[mobile_phone] =>
[work_email] =>
[private_email] =>
[joined_date] => 2015-08-11 00:00:00
[emp_salary] => 0
[confirmation_date] => 0000-00-00 00:00:00
[department] => HRM
[f_name] => dsad
[dob] => 1970-01-01
[c_address] =>
[domainName] =>
[emp_status] => active
)
[2] => stdClass Object
(
[id] => 13
[employee_id] => ST001
[emp_name] => Rakesh Negi
[gender] =>
[marital_status] =>
[address] =>
[postal_code] =>
[home_phone] =>
[mobile_phone] =>
[work_email] =>
[private_email] =>
[joined_date] => 2015-08-06 00:00:00
[emp_salary] => 0
[confirmation_date] => 0000-00-00 00:00:00
[department] => HRM
[f_name] => Father Name
[dob] => 1970-01-01
[c_address] =>
[domainName] =>
[emp_status] => active
)
)
,第二个数组就是这个
阵列
(
[0] => stdClass Object
(
[id] => 55
[emp_id] => ST001
[check_in] => 11:38:09
[check_out] => 00:00:00
[total_time] => 00:00:00
[status] =>
[date_time] => 2015-10-20
[emp_name] => Rakesh Negi
)
)
现在我想这样做
Array
(
[0] => stdClass Object
(
[id] => 14
[employee_id] => ST0011
[emp_name] => Munish Sharma
[gender] =>
[marital_status] =>
[address] =>
[postal_code] =>
[home_phone] =>
[mobile_phone] =>
[work_email] =>
[private_email] =>
[joined_date] => 1970-01-01 00:00:00
[emp_salary] => 0
[confirmation_date] => 0000-00-00 00:00:00
[department] => HRM
[f_name] => fname
[dob] => 1970-01-01
[c_address] =>
[domainName] =>
[emp_status] => active
)
[1] => stdClass Object
(
[id] => 12
[employee_id] => ST001dasd
[emp_name] => Rakesh Negi
[gender] =>
[marital_status] =>
[address] =>
[postal_code] =>
[home_phone] =>
[mobile_phone] =>
[work_email] =>
[private_email] =>
[joined_date] => 2015-08-11 00:00:00
[emp_salary] => 0
[confirmation_date] => 0000-00-00 00:00:00
[department] => HRM
[f_name] => dsad
[dob] => 1970-01-01
[c_address] =>
[domainName] =>
[emp_status] => active
)
[3] => stdClass Object
(
[id] => 55
[emp_id] => ST001
[check_in] => 11:38:09
[check_out] => 00:00:00
[total_time] => 00:00:00
[status] =>
[date_time] => 2015-10-20
[emp_name] => Rakesh Negi
)
)
如果两个数组中的em_id相同,我想从第一个数组中删除该值吗?
我尝试使用condion和join这样的
$date = date('Y-m-d');
$this->db->select('hrm_attendance.*,employees.emp_name');
$this->db->from('hrm_attendance');
$this->db->join('employees','hrm_attendance.emp_id=employees.employee_id','LEFT OUTER');
$this->db->where('hrm_attendance.date_time = "'.$date.'"');
$this->db->order_by('check_in','asc');
$query = $this->db->get();
return $query->result();
并获得此输出
(
[0] => stdClass Object
(
[id] => 55
[emp_id] => ST001
[check_in] => 11:38:09
[check_out] => 00:00:00
[total_time] => 00:00:00
[status] =>
[date_time] => 2015-10-20
[emp_name] => Rakesh Negi
)
)
但我想要上面描述的输出
如果我删除$this->db->where('hrm_attendance.date_time = "'.$date.'"');
行,那么我将从表中获取所有记录,我希望employee
表中的所有数据都包含所有ID,而只有来自hrm_attendance的数据{{1} 1}}可用于where条件
emp_id
答案 0 :(得分:2)
请检查代码点火器文档
http://www.codeigniter.com/userguide2/database/active_record.html#select
$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');
$query = $this->db->get();
// Produces:
// SELECT * FROM blogs
// JOIN comments ON comments.id = blogs.id
在选择(' *')中,您也可以指定有限的字段。
答案 1 :(得分:1)
您的bt
不正确db->where
http://www.codeigniter.com/user_guide/database/query_builder.html#selecting-data
$this->db->where('hrm_attendance.date_time = "'.$date.'"');
答案 2 :(得分:1)
我通过添加一些代码来找到解决方案
$date = date('Y-m-d');
$this->db->select('hrm_attendance.*,employees.emp_name');
$this->db->from('hrm_attendance');
$this->db->join('employees','hrm_attendance.emp_id=employees.employee_id','LEFT OUTER');
$this->db->where('hrm_attendance.date_time = "'.$date.'"');
$this->db->order_by('check_in','asc');
$query = $this->db->get();
$result = $query->result();
$count = count($result);
for($i = 0;$i<$count;$i++)
{
$id[] = $data['user_logged_in'][$i]->emp_id;
}
$this->db->select('*');
$this->db->from('employees');
$this->db->where_not_in('employee_id',$id);
$query = $this->db->get();
$data['absent'] = $query->result();
print_r($data['absent']);
通过使用这个,我得到了所有那些不在表hrm_attendance
中的员工