1

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.'"');

0

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I have updated my question again.Please check and see if you can do anything
Remove "LEFT OUTER" and change this line $this->db->where('hrm_attendance.date_time', $date); may be it help you
Thanks for the reply but getting the same output
1

In your db->where is incorrect $this->db->where('hrm_attendance.date_time = "'.$date.'"');

http://www.codeigniter.com/user_guide/database/query_builder.html#selecting-data

public function some_name() {

   $date = date('Y-m-d');

   $this->db->select('*');
   $this->db->from($this->db->dbprefix . 'hrm_attendance ha', 'LEFT');           
   $this->db->join($this->db->dbprefix . 'employees e', 'e.employee_id = ha.emp_id', 'LEFT');            
   $this->db->where('ha.date_time', $date);
   $this->db->order_by('check_in','ASC');
   $query = $this->db->get();

   return $query->result();

   // Or Try With result_array();

   // return $query->result_array();

}

Comments

1

I find out the solution by adding some code 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();
            $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']);

By using this I got the all those employee who are not in the table hrm_attendance

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.