2

I am working on a CodeIgniter project where i have to change the status of record. Actually I have to update only those records whose id are/is in the ids sting.

Currently, only one record is updated with my code. My model function is:

public function markUnRead() {
    $ids = 1,2,3,4,5,6;
    $update = array('status' => 0);
    $this->db->where_in('id', $ids);
    $this->db->update('tableName',$update);

    if ($this->db->affected_rows() > 0) {
        return true;
    } else {
        return false;
    }
}

Someone help me please.

1 Answer 1

3

The second parameter of where_in() method should be an array:

$this->db->where_in('id', array(1,2,3,4,5,6));

By any reason, if the $ids is an string like "1,2,3,4,5,6", you could get it to work by:

$ids = explode(',', $ids);
$this->db->where_in('id', $ids);
Sign up to request clarification or add additional context in comments.

3 Comments

I made the second parameter array but still got the same result. only one record is updated.
yes brother it works now , thank you very much, actually my changes were not correct. You answer is absolutely right. thanks once again.
I have the same problem and I have applied the same solution which you suggest here but I could not update multiple values, only single values get updated. What to do in this conditions? @HashemQolami

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.