【问题标题】:CodeIgniter update error?CodeIgniter 更新错误?
【发布时间】:2026-01-14 22:45:02
【问题描述】:

我在更新时遇到问题,这是我的看法:

foreach($attributes as $dataIndex ){
         $firstName = $dataIndex['first_name'];     
         $f = array(
        'name' => 'update_fname',
        'value' => $firstName
    );

  echo "<fieldset><label>First Name:</label></br>".form_input($f)."</br>";
  echo form_open(base_url()."index.php/home/save_update");
  echo "<label>".form_submit('save_updates','Save')."</label>";      

这里我已经在文本字段中显示了从我的数据库中获取的特定属性,但我想要做的是将更改的项目保存在文本字段中,并将其保存到具有特定 ID 的数据库中。

这是我的控制器以及 get 属性:

公共函数 get_attributes($patientID){

    if($patientID=== null){
       return;
}
  $data['attributes'] = $this>patient_manager>get_attributes($patientID);
  $this->load->view("edit_patient_view", $data);    

}

公共函数 save_update(){

if($this->input->post("save_updates") === false){
   return;
    }else{
$update = array( 'first_name' => $this->input->post('update_fname', true));
$this->patient_manager->save_attributes_by_id($update); 
    }

}这是为了保存

这是我的模型:

公共函数 get_attributes($patientID){

    $this->db->select('first_name, mid_name, 
    last_name, age, gender, b_day, marital_status, address, contact_num,
    occupation, medical_record');

    $this->db->from('patients');
    $this->db->where('patient_id', $patientID);
    return $this->db->get()->result_array();            
}

public function save_attributes_by_id($patientID, $update){

$this->db->where('patient_id', $patientID)
              ->update('patients', $update, $patientID);
}

我遇到了这个错误:

遇到了 PHP 错误

严重性:通知

消息:数组到字符串的转换

文件名:数据库/DB_active_rec.php

行号:427

发生数据库错误

错误号:1054

“where 子句”中的未知列“数组”

更新patients SET first_name = 0 其中patient_id = 数组

文件名:C:\xampp\htdocs\system\database\DB_driver.php

行号:330 我认为系统无法从我的数据库中获取 patient_id。 请提前帮助我。

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    试试这个 将数组设为

    $f = array(
                'update_fname' => $firstName);
    

    在这样的单个更新数组中,我们也可以使用批量更新

    通过这个链接

    http://ellislab.com/codeigniter/user-guide/database/active_record.html#update
    

    【讨论】:

      最近更新 更多