Welcome Guest, Not a member yet? Register   Sign In
Updating an existing database record with $this->db->set()
#1

[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
#2

[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]




Theme © iAndrew 2016 - Forum software by © MyBB