December 18th, 2012, 11:59 PM
-
Is it possible to avid this loop? (Thats a bad title for a question).
PHP Code:
public function edit_special_events($data)
{
foreach($data as $val=>$row)
{
$update_data = array('event_id' => $row);
$this->db->where('title', $val);
$this->db->update('sincity_special_events_banners', $update_data);
}
}
Thank you
December 19th, 2012, 01:22 AM
-
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.
December 19th, 2012, 01:42 AM
-
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')