How to get the data from both tables using join in codeigniter

advertisements

I have two array

 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
        )

)

and the second array is this

Array

(
    [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
        )

)

Now I want to make it like this

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
            )

)

I want to remove the value from first array if the em_id in the both array will be same is it possible in?

I tried using where condion with join like this

$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();

and getting this output

(
    [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
        )

)

But I want the output I have described above

if I remove $this->db->where('hrm_attendance.date_time = "'.$date.'"'); line then I am getting the all record from both the table I want all the data from the employee table with all ID and only those data from the hrm_attendance where the emp_id is available with where condition $this->db->where('hrm_attendance.date_time = "'.$date.'"');


Please check the Code igniter Docs

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

in select('*') you can specify your limited fields also.