CodeIgniter Forums
where_in method unexpected query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: where_in method unexpected query (/showthread.php?tid=1171)



where_in method unexpected query - rejoan - 02-16-2015

Hi,
I have a query like this
Code:
$this->db->where_in('chat_session', $latest_sessions)->update('chat_state', $update_state);

which generating following result

UPDATE `chat_state` SET `status` = 'exit'
WHERE `chat_session` IN('55_6_11,30_6_2')

But I need following query
UPDATE `chat_state` SET `status` = 'exit'
WHERE `chat_session` IN('55_6_11','30_6_2')

I have tried following still not working
Code:
$this->db->where_in('chat_session', $latest_sessions,NULL)->update('chat_state', $update_state);

and

Code:
$this->db->where_in('chat_session', $latest_sessions,FALSE)->update('chat_state', $update_state);



RE: where_in method unexpected query - Avenirer - 02-16-2015

is $latest_sessions an array? or is a string?. Do an echo. Does it output: '55_6_11 , 30_6_2'? if it does, then you know is not an array...


RE: where_in method unexpected query - SomeGuy - 02-16-2015

Seems like the following will do the trick. As Avenirer mentioned, it's most likely not an array.

$this->db->where_in('chat_session', explode(',', $latest_sessions))->update('chat_state', $update_state);


RE: where_in method unexpected query - rejoan - 02-17-2015

Thanks both @SomeGuy and @Avenirer. Got the idea, in fact the parameter should be an array