Welcome Guest, Not a member yet? Register   Sign In
Active Record - Incrementing a field - [resolved]
#1

[eluser]Unknown[/eluser]
Hi,

I am writing some code to increment a field in my database.

Code:
$data = array(
    'inc_field' => '(incField+1)'
);

$this->db->where('id', $id);
$this->db->update('my_table', $data);

I would normally write this as:
Code:
UPDATE my_table SET inc_field = (inc_field+1) WHERE id='{$id}'

CodeIgniter adds single quotes around (incField+1), as you would expect. However, this defeats my objective.

Is there a recommended way to achieve my goals? Or is my best alternative to modify the Active Record code?

Thanks,
David Edwards.

edit:

Code:
$this->db->set('inc_field', '(inc_field+1)', false);

This code filled my need. The false prevents escaping.
#2

[eluser]cahva[/eluser]
Yep thats it. Also you dont actually need the parentheses so you can leave them out.




Theme © iAndrew 2016 - Forum software by © MyBB