Incremental SET with active query not working - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Incremental SET with active query not working (/showthread.php?tid=54886) |
Incremental SET with active query not working - El Forum - 09-29-2012 [eluser]Dandy_andy[/eluser] 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? Code: $this->db->set('read', 'read + 1'); 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. Incremental SET with active query not working - El Forum - 09-29-2012 [eluser]PhilTem[/eluser] Third argument to set function call must be FALSE to avoid auto-escaping Code: $this->db->set('read', 'read + 1', FALSE); Source here Incremental SET with active query not working - El Forum - 09-30-2012 [eluser]Dandy_andy[/eluser] 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. Incremental SET with active query not working - El Forum - 10-01-2012 [eluser]smilie[/eluser] In you case, I would recommend: Code: $this->db->set('read = read + 1', '', FALSE); Cheers, Smilie Incremental SET with active query not working - El Forum - 10-01-2012 [eluser]Dandy_andy[/eluser] Ah, that makes sense! Thank you! |