繁体   English   中英

在 codeigniter 视图中查询非常慢

[英]Query in codeigniter view very slow

我在 codeigniter 视图中有这个查询,加载数据需要大约 10 分钟。 如果我删除第二个选择,它会正常加载。

任何人都可以看到导致这种情况的任何原因吗?

我可以在这里做些什么来缩短执行时间从而增加我的页面负载?

我的代码如下:

   <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> 

从查询中删除*并仅放置所需的列。 它将改善您的查询执行时间。 并在您使用WHERE子句的表列上添加索引,例如timestampteacher_id等。

它将根据需要尽快提高您的查询性能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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