Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 556
robins Avatar asked Oct 19 '22 23:10

robins


1 Answers

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.

like image 130
Disha V. Avatar answered Oct 22 '22 00:10

Disha V.