尝试在代码点火器活动记录中追加(添加到)小时列


trying to append (add to) hours column in codeigniter active record

我正在尝试在数据库中存储工作人员的工作时间。这样当他们结帐时,连续的小时数被添加到我的活动记录查询不起作用的那一天?

这是我在模型课上所做的。

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'); 
 }

查询是这样的,所以它不会读取小时变量

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

如何正确操作?

试试这段代码:

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

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'); 
 }