CodeIgniter Forums
Updating an existing database record with $this->db->set() - 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: Updating an existing database record with $this->db->set() (/showthread.php?tid=13179)



Updating an existing database record with $this->db->set() - El Forum - 11-13-2008

[eluser]Jose Dueñas[/eluser]
Hi,
I'm not sure what I'm doing wrong, It's something very imple but I don't get it working...

I want to update an existing record in my database:
Code:
UPDATE articles
SET views = views + 1
WHERE id = $id

so I'm doing:
Code:
$this->db->set('views', 'views + 1');
$this->db->where('id', $id);
$this->db->update('articles');

But I only get, the 'views' set to 0.

Thanks,
Jose


Updating an existing database record with $this->db->set() - El Forum - 11-13-2008

[eluser]Jose Dueñas[/eluser]
Ok,
I forgot to set the third paremeter for the db->set to FALSE in order to escape.
This works:
Code:
$this->db->set('views', 'views + 1',FALSE);
$this->db->where('id', $id);
$this->db->update('articles');

Many hours in the computer, i'm going for a rest.. hehe

Thanks!

[quote author="Jose Dueñas" date="1226628827"]Hi,
I'm not sure what I'm doing wrong, It's something very imple but I don't get it working...

I want to update an existing record in my database:
Code:
UPDATE articles
SET views = views + 1
WHERE id = $id

so I'm doing:
Code:
$this->db->set('views', 'views + 1');
$this->db->where('id', $id);
$this->db->update('articles');

But I only get, the 'views' set to 0.

Thanks,
Jose[/quote]