0

I have to update my table data where id in (1,2,3,4,5).

How can I implement this query in CodeIgniter?
What I have tried:

$id_list = '1,2,3,4,5';
$this->db->where_in('id', $id_list);
$this->db->update('my_table', $mydata);

But it's not working.

1

2 Answers 2

2

in where_in, you have to pass array. currently you are passing string. change your code as below:

$id_list = '1,2,3,4,5';
$id_list = explode(",",$id_list);
$this->db->where_in('id', $id_list);
$this->db->update('my_table', $mydata);
Sign up to request clarification or add additional context in comments.

Comments

2

$id_list should be an array() to work with where_in

Here is the code :

$id_list = array(1,2,3,4,5);
$this->db->where_in('id', $id_list);
$this->db->update('my_table', $mydata);

for more : https://www.codeigniter.com/user_guide/database/query_builder.html

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.