Welcome Guest, Not a member yet? Register   Sign In
Incremental SET with active query not working

Ok, so where am I going wrong here... I just want to increment a value by 1 but it doesn't seem to work. I've checked all field names and all is correct. I'm using two WHERE statements - is that where the problem is?

$this->db->set('read', 'read + 1');
$this->db->where('section_id', $section_id);
$this->db->where('ID', $post_id);

I've checked the values of $section_id and $post_id and both are returning the correct numeric value. But the column READ isn't being updated in my DB... Any ideas? Thx.

Third argument to set function call must be FALSE to avoid auto-escaping Wink
$this->db->set('read', 'read + 1', FALSE);

Source here

Thanks, but when I did that, I got an SQL syntax error... "read + 1 WHERE `section_id` = `1` AND `ID` = `6` at line 1"

UPDATE `forum_posts` SET `read` = read + 1 WHERE `section_id` = `1` AND `ID` = `6`

However, I could see that the "read + 1" syntax wasn't escaped so by adding `` around the last read, it seems to have solved the issue.

In you case, I would recommend:

$this->db->set('read = read + 1', '', FALSE);


Ah, that makes sense! Thank you!

Theme © iAndrew 2016 - Forum software by © MyBB