我有时间记录表
date
time in
time out
break in
break out
total_time
我表中的字段。我有这个SQL查询
public function showattendance(){
$start = $this->input->post('DATE_FROM');
$end = $this->input->post('DATE_TO');
$employee = $this->input->post('ID_NUM');
$sql = "SELECT * FROM `attendance` WHERE (DATE BETWEEN '".$start."' AND '".$end."') AND (ID_NUM = '".$employee."')";
$query = $this->db->query($sql);
return $query->result();
}
现在我想要做的就是当我选择了我选择的日期之间的行时,我想添加total_time
列中的所选数据。
例如我有一个
数组array = (
ID[0] => '1' , TOTAL_TIME[0]=>'09:30'
ID[1] => '2' , TOTAL_TIME[1]=>'07:30'
ID[2] => '3' , TOTAL_TIME[2]=>'08:30'
ID[3] => '4' , TOTAL_TIME[3]=>'09:00'
ID[4] => '5' , TOTAL_TIME[4]=>'05:45'
);
我想做的就是添加
TOTAL_TIME[0]+TOTAL_TIME[1]+TOTAL_TIME[2]+TOTAL_TIME[3]+TOTAL_TIME[4] = $value
答案 0 :(得分:1)
将结果转换为数组时,这样做非常简单。这可能会帮助您解决问题。
Here one column is later updated with new values in php. This may be helpful.
--------------更新后的答案------------
然后你的数组应该像
<?php
$x = array(
array( ID => '1' , TOTAL_TIME =>'09:30'),
array( ID => '2' , TOTAL_TIME =>'07:30'),
array( ID => '3' , TOTAL_TIME =>'08:30'),
array( ID => '4' , TOTAL_TIME =>'09:00'),
array( ID => '5' , TOTAL_TIME =>'05:45'));
$total;
foreach($x as $y){
$total+=$y["TOTAL_TIME"];
}
echo "Total Time = ".$total;
?>
因此,您可以获得总时间。
答案 1 :(得分:0)
据我所知,你需要添加从start_date到end_date的句点来运行这段代码:
$res = $this->showattendance();// this is from your code
$this->db->update("time-recods");
$this->db->set("total_time",date_diff($res->time_in,$res->time_out));
$this->db->where('ID_NUM',$employee);
我希望它会对你有所帮助:)。