【问题标题】:How can I update data with arrays in CodeIgniter如何在 CodeIgniter 中使用数组更新数据
【发布时间】:2022-01-26 05:56:07
【问题描述】:

我在更新数据时遇到了问题,出现了Array of String 错误 我正在使用 MVC,CodeIgniter。

我所做的是导入 excel 文件并更新系统中的数据。我想更新您可以在模型上看到的数据。首先,我正在尝试使用静态数据来检查它是否有效,请参阅模型。请不要重复,因为每个问题都有不同的解决方法。感谢您抽出宝贵时间。

型号:

   public function updateGrades($updateFields){  
        $this->db->where('studentID', 200171419);
        $this->db->where('updtStatus', 1);
        return $this->db->update('tbl_tt_academicinfo', $updateFields);
    }

【问题讨论】:

标签: php codeigniter codeigniter-3


【解决方案1】:

只要$updateFields是一个多维数组并且codeigniter更新函数处理一维数组['key'=>'value'],你必须像这样在for循环中使用更新查询

 public function updateGrades($updateFields){  
        foreach($updateFields as $recoredData){
            $this->db->where('studentID', 200171419); // prefer to make it dynamic $recoredData['studentID']
            $this->db->where('updtStatus', 1);
            $this->db->update('tbl_tt_academicinfo', $recoredData);
        }
    }

【讨论】:

    【解决方案2】:
    public function updateGrades($updateFields){  
       $this->db->where('updtStatus', 1);        
       return $this->db->update_batch('tbl_tt_academicinfo', $updateFields, 'studentID');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      • 2019-12-20
      相关资源
      最近更新 更多