简体   繁体   中英

Using an array in a MySql WHERE clause in CodeIgniter

I want to take the conversation_id values from the following arrays and store them into another array so I can use it in a WHERE clause. Is that possible?

`Array ( [conversation] => Array ( 
[0] => Array ( 
[conversation_id] => 4
[conversation_subject] => This is just a test 
[conversation_last_reply] => 2016-01-03 20:12:14 
[conversation_unread] => 1 ) 
[1] => Array (
[conversation_id] => 3 
[conversation_subject] => Interview scheduled for monday [conversation_last_reply] => 2016-01-03 18:51:33 
[conversation_unread] => 1 ) 
[2] => Array ( 
[conversation_id] => 2 
[conversation_subject] => Google hangout
[conversation_last_reply] => 2016 [conversation_unread] => 1 )
[3] => Array ( 
[conversation_id] => 1 
[conversation_subject] => testing 
[conversation_last_reply] => 2016
[conversation_unread] => 1 ) ) )`

My frame work is codeignitor

我建议您熟悉PHP的内置foreach()函数。

You can defined a new array and populate that with the conversation_id and you will be using $this->db->where_in() to get the result.

$where = [];
foreach($array['conversation'] as $row){
   $where[] = $row['conversation_id'];
}

// Model code

$this->db->where_in('conversation_id', $where);

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM