简体   繁体   中英

Query in codeigniter view very slow

I have this query inside a codeigniter view and it takes about 10 minutes to load the data. If I remove the second select it loads pretty normally.

Could anyone see any reason to cause this?

Is there anything I can do here to improve the execution time and therefore increase my page load?

My code is as follows:

   <tbody>
                    <?php 
//$this->db->select('teacher.*,teacher_attendance.*');

$this->db->select('teacher.teacher_id,teacher.name,teacher_attendance.*');                    

$this->db->from('teacher_attendance');
$this->db->where ('timestamp', $timestamp);
$this->db->group_by('teacher.teacher_id');
$this->db->join('teacher', 'teacher.teacher_id = teacher_attendance.teacher_id', 'left'); 
//$this->db->limit(50);
$teachers   =$this->db->get()->result_array();

                                   foreach($teachers as $row){

                               ?>
                        <tr>
                            <td><?php echo $row['teacher_id'];?></td>
                            <td><img src="<?php //echo $this->crud_model->get_image_url('teacher',$row['teacher_id']);?>" class="img-circle" width="30" /></td>
                            <td><?php echo $row['name'];?></td>

                            <td>

                           <select id="selected1" class="sele1 form-control selectboxit" name="status_<?php echo $row['attendance_id']; ?>">
                                    <option value="0" <?php if ($row['status'] == 0) echo 'selected'; ?>><?php echo get_phrase('undefined'); ?></option>
                                    <option value="1" <?php if ($row['status'] == 1) echo 'selected'; ?>><?php echo get_phrase('present'); ?></option>
                                    <option value="2" <?php if ($row['status'] == 2) echo 'selected'; ?>><?php echo get_phrase('absent'); ?></option>
                                </select>

                                 <!--    <input type="radio" name="status_<?php echo $row['attendance_id']; ?>" value="1"  <?php if ($row['status'] == 1) echo 'checked'; ?>/>
    &nbsp;
    <input type="radio" name="status_<?php echo $row['attendance_id']; ?>" value="2"  <?php if ($row['status'] == 2) echo 'checked'; ?> />
                          -->  
                            </td>
      <td>

      <select class="form-control selectboxit" name="leave_status<?php echo $row['attendance_id']; ?>">
                                    <option value="0" <?php if ($row['leave_status'] == 0) echo 'selected'; ?>><?php echo get_phrase('undefined'); ?></option>
                                    <option value="1" <?php if ($row['leave_status'] == 1) echo 'selected'; ?>><?php echo get_phrase('CASUAL'); ?></option>
                                    <option value="2" <?php if ($row['leave_status'] == 2) echo 'selected'; ?>><?php echo get_phrase('MEDICAL'); ?></option>
                                    <option value="3" <?php if ($row['leave_status'] == 3) echo 'selected'; ?>><?php echo get_phrase('DUTY'); ?></option>
                                    <option value="4" <?php if ($row['leave_status'] == 4) echo 'selected'; ?>><?php echo get_phrase('HALF DAY'); ?></option>
                                    <option value="5" <?php if ($row['leave_status'] == 5) echo 'selected'; ?>><?php echo get_phrase('OTHER'); ?></option>
                                    <option value="6" <?php if ($row['leave_status'] == 6) echo 'selected'; ?>><?php echo get_phrase('LATE'); ?></option>
                                    <option value="7" <?php if ($row['leave_status'] == 7) echo 'selected'; ?>><?php echo get_phrase('SHORT'); ?></option>

                                </select> 

Remove * from the query and put only required colums. It will improve your query execution time. And also add index on table column on which you are using WHERE clause like timestamp , teacher_id , etc.

It will improve your query performance as fast as required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM