[英]Query in codeigniter view very slow
I have this query inside a codeigniter view and it takes about 10 minutes to load the data.我在 codeigniter 视图中有这个查询,加载数据需要大约 10 分钟。 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'; ?>/>
<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.并在您使用WHERE
子句的表列上添加索引,例如timestamp
、 teacher_id
等。
It will improve your query performance as fast as required.它将根据需要尽快提高您的查询性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.