CodeIgniter Forums
Activerecord -> field=field+1 - 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: Activerecord -> field=field+1 (/showthread.php?tid=11191)



Activerecord -> field=field+1 - El Forum - 08-29-2008

[eluser]shaffick[/eluser]
Hey guys,

I'm just wondering how to do an update and have

"update table set field=field+1"

i checked out the code for the mysql driver etc, it doesn't seem like i can do it through active records...anyone?

cheers


Activerecord -> field=field+1 - El Forum - 08-29-2008

[eluser]Thorpe Obazee[/eluser]
Code:
$this->db->where('id', $this->tutorial_id);
$this->db->set('tutorial_views', 'tutorial_views + 1', FALSE);
$this->db->update('tutorials');

I believe you need something like this.


Activerecord -> field=field+1 - El Forum - 08-29-2008

[eluser]shaffick[/eluser]
yeah, that is correct. However, I have multiple fields to update and set doesnt take arrays.

Ah well, I'll just rework my code a bit. Thanks for the reply. If someone else has any ideas, shoot 'em my way.


Activerecord -> field=field+1 - El Forum - 08-29-2008

[eluser]Thorpe Obazee[/eluser]
Code:
$array = array('name' => 'name + 1', 'title' => 'title + 1', 'status' => 'status + 1');
$this->db->set($array, FALSE);
$this->db->insert('mytable');

maybe this could work.


Activerecord -> field=field+1 - El Forum - 08-29-2008

[eluser]shaffick[/eluser]
I just had a quick glace: system/database/db_active_rec.php, line 974.

I don't think it does. My brain is fried right now anyway, will revisit this later.

Thanks for your help.


Activerecord -> field=field+1 - El Forum - 08-29-2008

[eluser]Thorpe Obazee[/eluser]
haha. yeap me too... it's 4am here and I don't even know if I am still thinking straight.

agreed :p


Activerecord -> field=field+1 - El Forum - 09-16-2008

[eluser]shaffick[/eluser]
edit: n/m. wrong info posted.