CodeIgniter Forums
Active Record method chaining syntax - 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: Active Record method chaining syntax (/showthread.php?tid=42001)



Active Record method chaining syntax - El Forum - 05-23-2011

[eluser]DrDave[/eluser]
Can someone tell me the correct syntax for chaining an active record update statement, or where I can find examples? I want to chain this just to get a handle on how chaining works:

Code:
$data = array( 'user_color' => 'blue' );
$this->db->where('user_id', $user_id);
$this->db->update('user', $data);

Thanks!


Active Record method chaining syntax - El Forum - 05-23-2011

[eluser]jmb727[/eluser]
[quote author="DrDave" date="1306198989"]Can someone tell me the correct syntax for chaining an active record update statement, or where I can find examples? I want to chain this just to get a handle on how chaining works:

Code:
$data = array( 'user_color' => 'blue' );
$this->db->where('user_id', $user_id);
$this->db->update('user', $data);

Thanks![/quote]

What do you mean by chaining?
Do you mean updating multiple table fields using an array with keys/values representing fields/new values?


Active Record method chaining syntax - El Forum - 05-23-2011

[eluser]cahva[/eluser]
You just chain it like this:
Code:
$data = array( 'user_color' => 'blue' );
$this->db->where('user_id', $user_id)->update('user', $data);



Active Record method chaining syntax - El Forum - 05-23-2011

[eluser]DrDave[/eluser]
Oh, that simple Smile I was trying to do it without the array and couldn't figure out where to put 'blue'. Thanks!