Php 试图在codeigniter活动记录中追加(添加到)小时数列

Php 试图在codeigniter活动记录中追加(添加到)小时数列,php,mysql,codeigniter,activerecord,Php,Mysql,Codeigniter,Activerecord,我试图在数据库中存储工作人员的工作时间。这样,当他们结账时,连续的小时数被添加到我的活动记录查询无法工作的当天 下面是我在模型课上所做的 function update_daily_row($email,$date,$hours)//update existing row. { $this->db->where('email', $email); $this->db->where('date', $date); $this->d

我试图在数据库中存储工作人员的工作时间。这样,当他们结账时,连续的小时数被添加到我的活动记录查询无法工作的当天

下面是我在模型课上所做的

function update_daily_row($email,$date,$hours)//update existing row.
{

      $this->db->where('email', $email);
      $this->db->where('date', $date);
      $this->db->set('hours', 'hours + $hours', FALSE);
      $this->db->update('dailyinfo'); 
 }
查询结果如下,因此它不读取hours变量

UPDATE `tablename` SET `hours` = hours + $hours WHERE `email` = 'email@yahoo.com' AND     `date` = '2013-10-08'

如何正确操作?

你应该先读出小时数,然后再加上$hours

function update_daily_row($email,$date,$hours)//update existing row.
{

      $this->db->where('email', $email);
      $this->db->where('date', $date);

      $origin_hours = $this->db->get('dailyinfo')->first_row()->hours;
      $update_hours = $original_hour + $hours;

      $this->db->set('hours', $update_hours, FALSE);
      $this->db->update('dailyinfo'); 
 }
请尝试以下代码:

function update_daily_row($email,$date,$hours)//update existing row.
{
      $this->db->where('email', $email);
      $this->db->where('date', $date);
      $this->db->set('hours', 'hours + '. $hours, FALSE);
      $this->db->update('dailyinfo'); 
}

如果它解决了你的问题,请接受它作为答案,谢谢!请在你的回答中加上一些解释。只显示代码可能会让人困惑。这比公认的答案要好-您不必在更新字段之前加载它