我在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'; ?>/>
<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>
答案 0 :(得分:0)
从查询中删除*
,仅放入所需的列。这将缩短您的查询执行时间。并在使用WHERE
,timestamp
等teacher_id
子句的表列上添加索引。
它将按要求快速提高查询性能。