0
votes

I'm having a problem on updating here is my view:

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>";      

here I already showed in text field the obtained specific attributes from my database but the thing that I want to do is to save the changed item in the text field and save it to the database with a specific id.

here is my controller along with the get attributes:

public function get_attributes($patientID){

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

}

public function 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); 
    }

} this is for saving

here is my model:

public function 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);
}

and I'm having this error:

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: database/DB_active_rec.php

Line Number: 427

A Database Error Occurred

Error Number: 1054

Unknown column 'Array' in 'where clause'

UPDATE patients SET first_name = 0 WHERE patient_id = Array

Filename: C:\xampp\htdocs\system\database\DB_driver.php

Line Number: 330 I think the the system can't get the patient_id from my database. pls help me thatks in advance.

1

1 Answers

0
votes

Try this one Make array as

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

in single updation array set like this, we can use batch updation also

go through this link

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