i use the simple query in my sql like
$query="update employee set employee_salary=employee_salary+ '".$bones.'" where employee_id='".$data['employee_id']."' and employee_code='".$data['employee_code']."'";
i use the following code but does not work as below
$this->db->where('employee_id', $data['employee_id']);
$this->db->where('employee_code', $data['employee_code']);
$this->db->set('employee_salary', 'employee_salary+ $bones', FALSE);
$this->db->update('spar_m_in_out');
Now i want to update employee salary update with current value with bones
You should update the third line as below:
$employee_salary = $employee_salary + $bones
$this->db->set('employee_salary', $employee_salary ), FALSE);
The variable isn't interpreted since it's inside single quotes, and gets passed down as is.
Concatenate the string so as to evaluate the variable and pass it as a whole string expression to the DB:
$this->db->set('employee_salary', 'employee_salary + '.$bones, FALSE);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.