nested forloop with if else statement php codeigniter
<p><a href="http://i.stack.imgur.com/s6AMo.png" rel="nofollow">View image</a>
<div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>my controller
public function admin() {
        $data['employee'] = $this-&gt;attendance_model-&gt;get_attendance();
        // get today's all employee attendance details
        $data['attendance'] = $this-&gt;attendance_model-&gt;attendance();
        // attendance page
        $data['header'] = "Employee";
        $data['sub_header'] = "Attendance employee";
        $data['main_content'] = 'attendance/admin_list';
        $this-&gt;load-&gt;view('employeelayout/main',$data);
    }

my model
// get the employee details
    public  function get_attendance () {
        return $this-&gt;db-&gt;get('employee')-&gt;result();
    }
    
    public function attendance() {
        $today = date('Y-m-d');  // get today date
        $this-&gt;db-&gt;where('A.date',$today)-&gt;from('attendance A')
        -&gt;join('employee E','E.employee_id = A.employee_id','LEFT');
        return $this-&gt;db-&gt;get()-&gt;result();
    }</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;thead&gt;
                &lt;tr&gt;
                    &lt;th&gt;#&lt;/th&gt;             
                    &lt;th&gt;Employee Name&lt;/th&gt;
                    &lt;th&gt;Employee Number&lt;/th&gt;
                     &lt;th&gt;Today&lt;/th&gt;
                    &lt;th&gt;Mark Incoming&lt;/th&gt;       
                    &lt;th class="hidden-phone"&gt;Status&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
           
            &lt;tbody&gt;
                &lt;?php $count = 1; ?&gt;
                &lt;?php foreach($employee as $emp) {  ?&gt;
                 
               &lt;tr class="gradeX"&gt;
                    &lt;td&gt;&lt;?php echo $count ++ ?&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;?php echo $emp-&gt;first_name.' '.$emp-&gt;last_name ?&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;?php echo $emp-&gt;employee_number ?&gt;&lt;/td&gt;
                    &lt;?php foreach($attendance as $atten) {  ?&gt;
                    
                    &lt;?php if($emp-&gt;employee_id == $atten-&gt;employee_id) { ?&gt; 
                    &lt;td&gt;&lt;?php echo $atten-&gt;date ?&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;?php echo $atten-&gt;mark_in_time ?&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;?php echo "present" ?&gt;&lt;/td&gt;
                    &lt;?php } else {  ?&gt;
                    &lt;td&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;?php echo "absent" ?&gt;&lt;/td&gt;
                    &lt;?php } ?&gt;
                    &lt;?php } ?&gt;
               &lt;/tr&gt; 
               
                &lt;?php } ?&gt;
            &lt;/tbody&gt;</code></pre>
</div>
</div>
</p>

<p>i used nested foreach ,
1st I display the all employee in first foreach
2nd i want to display the employee attendance with present and absent 
from attendance table I match employee_id with employee table of employee_id
where it display the all present employee and it properly displaying the absent. any help please</p>

<p>i posted the image, you can see, i display all the employees, i'm checking if employee-id = employee-id (means exist in the attendance table). if exists display "present" else "absent". but it over looping.</p>