I am trying to store hours for a worker in a database. So that when they checkout the hours in a row are added to for the day my active record query wont work though?
Here is what i am doing in my model class.
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');
}
The query comes out like this so it doesnt read the hours variable
UPDATE `tablename` SET `hours` = hours + $hours WHERE `email` = 'email@yahoo.com' AND `date` = '2013-10-08'
How to do it properly?
You should read the hours out first and then add it $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');
}
Try this code:
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');
}