Update multiple Rows in Codeigniter

前端 未结 3 1065
闹比i
闹比i 2020-12-16 20:41

I have been looking around but I have not found an answer yet. Kindly help if you know the answer.

How do you update multiple rows in CI?

In my MySQL:

<
3条回答
  •  情歌与酒
    2020-12-16 20:56

    There is indeed an update_batch() method available in CodeIgniter already.

    You can use it your example like so:

    $data = array(
        array(
            'ID' => 1,
            'Settings Name' => 'Hello',
            'Settings Value' => 'True'
        ),
        array(
            'ID' => 2,
            'Settings Name' => 'World',
            'Settings Value' => 'Good'
        )
    );
    $this->db->update_batch('tableName', $data, 'id'); 
    

    So what you have is an array of arrays, the children basically hold the data for each row in the database. The first parameter for update_batch() is the name of the database table, the second is the $data variable and the third is the column you want to use in the WHEN clause.

提交回复
热议问题