代码之家  ›  专栏  ›  技术社区  ›  kev_m

在代码点火器中添加选定范围内的列值[复制]

  •  0
  • kev_m  · 技术社区  · 9 年前

    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
    
    2 回复  |  直到 1 年前
        1
  •  1
  •   Community CDub    8 年前

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

        2
  •  0
  •   Mhd Wael Jazmati    9 年前

    $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); 
    

    我希望它能帮助你:)