Update batch with CodeIgniter

后端 未结 2 865
旧时难觅i
旧时难觅i 2021-01-02 07:43

I\'m trying to do a small open CMS with CodeIgniter and I\'m now working on the categories system.

I\'m really stuck with that and after many tries and forum post I

2条回答
  •  星月不相逢
    2021-01-02 08:27

    try to use UPDATE_BATCH

    $this->db->update_batch();
    
    
    
    $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'
       )
    );
    
    $this->db->update_batch('mytable', $data, 'title'); 
    

    The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key.

    hope this help........................

    UPDATE 
    
    // 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')
    

提交回复
热议问题