
December 19th, 2012, 01:42 AM
|
 |
A Change of Season
|
|
|
|
Quote: | Originally Posted by requinix You don't need $update_data since you could just put the array right in the function call, but otherwise no I don't see any way you can get rid of the loop. | Oh I just found $this->db->update_batch('mytable', $data, 'title');
PHP Code:
$data = array(
array(
'title' => 'My title' ,
'name' => 'My Name 2' ,
'date' => 'My date 2'
),
array(
'title' => 'Another title' ,
'name' => 'Another Name 2' ,
'date' => 'Another date 2'
)
);
// Produces:
// UPDATE `mytable` SET `name` = CASE
// WHEN `title` = 'My title' THEN 'My Name 2'
// WHEN `title` = 'Another title' THEN 'Another Name 2'
// ELSE `name` END,
// `date` = CASE
// WHEN `title` = 'My title' THEN 'My date 2'
// WHEN `title` = 'Another title' THEN 'Another date 2'
// ELSE `date` END
// WHERE `title` IN ('My title','Another title')
|