#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,664
    Rep Power
    171

    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
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,068
    Rep Power
    9398
    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.
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,664
    Rep Power
    171
    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') 

IMN logo majestic logo threadwatch logo seochat tools logo