Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Codeigniter中只更新了一行_Php_Mysql_Codeigniter - Fatal编程技术网

Php 在Codeigniter中只更新了一行

Php 在Codeigniter中只更新了一行,php,mysql,codeigniter,Php,Mysql,Codeigniter,下面是我的模型代码,当我尝试更新它时,它只更新第一行,而不更新其他行。我也尝试使用update_batch,但它返回一个数据库错误页面 My Model Code: foreach ($ingredients as $item) { // $this->sma->print_arrays($item); if($item['id']){ $this->db->where('id', $item['id']);

下面是我的模型代码,当我尝试更新它时,它只更新第一行,而不更新其他行。我也尝试使用update_batch,但它返回一个数据库错误页面

   My Model Code:
      foreach ($ingredients as $item) {
        //  $this->sma->print_arrays($item);
       if($item['id']){
       $this->db->where('id', $item['id']);
       $this->db->update('items', $item);
       // }
       return true;
     }
我的数组:(配料)


我们将感谢您的帮助

使用
update\u batch
更新一组数据

$data = array(
    [0] => Array
    (
        [id] => 16
        [quantity] => 76
    )

    [1] => Array
    (
        [id] => 92
        [quantity] => 97
    )
);

$this->db->update_batch('tableName', $data, 'id');

由于返回true;inside loop.remove返回语句。@MubasharIqbal Ohh!!谢谢。。那真的很快,你让我的工作更轻松;)使用
update_batch('items',$components,'id')一次更新所有内容。所有数组都应该是相同的。任何关于返回true导致问题的想法,我对php来说都是新手,所以简单的解释会让我更好地理解。我刚刚在循环中删除了返回,它成功了。谢谢
$data = array(
    [0] => Array
    (
        [id] => 16
        [quantity] => 76
    )

    [1] => Array
    (
        [id] => 92
        [quantity] => 97
    )
);

$this->db->update_batch('tableName', $data, 'id');