1

i had recently gotten help updating multiple data in the database using codeigniter. but on running the code i got Message: Undefined index: id

Controller

public function update_record()
{
    $id = ["19821", "19923", "19966", "19967"];
    $total = ["8", "118", "90", "100"];
    $update_data = [];
    foreach ($id as $key => $value) {
        $update_data[] = [
            'id'    => $value,
            'total' => $total[$key]
        ];
    }

    if ($this->some_model->batch_data('records', $update_data) == true) {
        echo "yes";
    } else {
        echo "no";
    }

}

Model

public function batch_data($table, $data)
{
    $this->db->update_batch($table, $data, 'id'); // this will set the id column as the condition field
    return true;
}

Running this i got:

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index: id</p>
<p>Filename: database/DB_query_builder.php</p>
<p>Line Number: 1949</p>
courage
  • 115
  • 3
  • 20

0 Answers0