robins
robins

Reputation: 1668

Update multiple ids in codeigniter

I want to update data to multiple ids, I take all ids

controller

    public function getIds(){
    for($i=0;$i<count($_POST['std_id']);$i++){
        echo $_POST['std_id'][$i];
        $student_id[]=$_POST['std_id'][$i];
    } 

I don't know how to update this?

How to write the modal function?

Upvotes: 6

Views: 4958

Answers (1)

Disha V.
Disha V.

Reputation: 1864

You don't have to create separate array for that. You can pass $_POST['std_id] which is having array of ids.

controller

$this->modelname->mymethod($_POST['std_id'],$updateData);

where $_POST['std_id'] is an array of ids and $updateData for updating fields

model

function mymethod($idArr,$data){
    $this->db->where_in("fieldname", $idArr);
    $this->db->update("tablename",$data);
}

you can use where_in for mysql IN to check multiple ids.

Upvotes: 5

Related Questions