CodeIgniter Forums
active record CONCAT - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: active record CONCAT (/thread-15699.html)



active record CONCAT - El Forum - 02-12-2009

[eluser]NZmuzzer[/eluser]
Anyone know how to CONCAT an existing text field with new text using Active Record? Is this possible?

I'll explain that a little better. I have a field in one of my tables called "log" which has existing text in it, and I wish to append text such as "updated on 12 Feb 08" to the end of this field. I know I could query the database to return the record and extract the field text, and then update the table it with the new concatanated text, but that seems an awful long way of doing something simple.

I believe I can do something like
Code:
$this->db->set('field', 'field+1', FALSE);
for numeric fields, but how about text?


active record CONCAT - El Forum - 02-12-2009

[eluser]xwero[/eluser]
Did you try the concat function?
Code:
$this->db->set('field', 'CONCAT(field,field2)', FALSE);



active record CONCAT - El Forum - 02-12-2009

[eluser]TheFuzzy0ne[/eluser]
It should be noted, however, that CONCAT is database specific. It's not actually a part of the active record library, although I'm sure it's supported by most, if not all database engines.


active record CONCAT - El Forum - 02-12-2009

[eluser]NZmuzzer[/eluser]
Thanks xwero, that worked a treat.