title: How to reduce the loading time of data mysql, codeigniter
body: <p>I have like 400 plus records to retrieve from this method and it almost takes 2 minutes to load the page. So please help me how to reduce the loading time of this method.</p>
  
  <pre><code>function teacher_attendance_selector()
  
      {
  
          $data['year']       = $this-&gt;input-&gt;post('year');
          $data['timestamp']  =strtotime($this-&gt;input-&gt;post('timestamp'));
          $query = $this-&gt;db-&gt;get_where('teacher_attendance' ,array(
                    'teacher_id'=&gt;$data['teacher_id'],
               'year'=&gt;$data['year'],
  
          ));
  
  
  
          if($query-&gt;num_rows() &lt; 1) {
              $teachers = $this-&gt;db-&gt;get_where('teacher' , array(
  
              ))-&gt;result_array();
  
              foreach($teachers as $row) {
                  $attn_data['year']       = $data['year'];
                  $attn_data['timestamp']  = $data['timestamp'];
                  $attn_data['teacher_id'] = $row['teacher_id'];
  
                  $this-&gt;db-&gt;insert('teacher_attendance' , $attn_data);  
              }
  
          }
    redirect(base_url().'index.php?admin/manage_teacher_attendance_view/'.$data['timestamp'],'refresh');
          }
  </code></pre>