0

Morning guys,

I would like to update multiple row using explode function and where in for code igniter, but the problem is, all rows all updated.

here is my controller :

$ids = explode(',', $this->post('id'));
$this->chatmod->update(array('id'=>$ids),$data);

my model :

public function update($ids=null,$data=null)
    {
        $this->db->where_in($ids);
        $this->db->update($this->table, $data);
        return true;
    }
1
  • $ids is an array? Commented Apr 9, 2018 at 7:05

2 Answers 2

1

For updating using column id you need to pass the column name in the where_in function like $this->db->where_in("id",$idarray);

For your code Try the below code:

public function update($ids=null,$data=null)
{
    $this->db->where_in('id',$ids);////Pass the column name of the database as first argument.
    $this->db->update($this->table, $data);
    return true;
}
Sign up to request clarification or add additional context in comments.

Comments

1

The where_in query should be supplied with target column, like :

$ids = explode(',', $this->post('id'));
$this->chatmod->update($ids,$data);

public function update($ids=null,$data=null)
    {
        $this->db->where_in('id', $ids);
        $this->db->update($this->table, $data);
        return true;
    }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.