Skip to content
Advertisement

How to update multiple records in Codeigniter

public function asset_rep()
{
    $astid = $this->input->post("astid");
    //print_r($astid);die;
    $astrep_id = $this->input->post("astrep_id");
    $this->asset_model->update_asset_rep($astid,$astrep_id);
    redirect("asset/index");
}

public function update_asset_rep($astid,$astrep_id)
{
    $astrep = implode(',', $astid);
    echo $astrep;
    $this->db->where('id',$astrep);
    $this->db->update('pm1asset',array('owner' =>$astrep_id));
    echo $this->db->last_query(); 
}

In above code snippet first function is declared in controller and second function is declared in model. I want to update owner for multiple rows having ids in $astrep. Can anyone please help me?

Advertisement

Answer

You can use whereIn() or orWhereIn() methods from query builder class.

Refer https://codeigniter4.github.io/userguide/database/query_builder.html#looking-for-specific-data

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement