Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在CodeIgniter中的MySql WHERE子句中使用数组_Php_Mysql_Arrays_Codeigniter - Fatal编程技术网

Php 在CodeIgniter中的MySql WHERE子句中使用数组

Php 在CodeIgniter中的MySql WHERE子句中使用数组,php,mysql,arrays,codeigniter,Php,Mysql,Arrays,Codeigniter,我想从以下数组中获取conversation\u id值,并将它们存储到另一个数组中,以便在WHERE子句中使用它。可能吗 `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\u id
值,并将它们存储到另一个数组中,以便在
WHERE
子句中使用它。可能吗

`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 ) ) )`

我的框架是codeignitor

我建议您熟悉PHP的内置函数

您可以定义一个新数组,并用
对话id
填充该数组,以及 您将使用
$this->db->where_in()
获得结果

$where = [];
foreach($array['conversation'] as $row){
   $where[] = $row['conversation_id'];
}
//模型代码

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

希望这能有所帮助。

我知道如何为每个循环执行一个循环。但是我该怎么做where子句呢?我会让它内爆吗?我试过了。从未工作您是否在查询中使用SELECT
*
?没有,先生。我正在选择我加入的大约3个表中的字段。我想为每个会话id值运行where子句。无论哪种方式,您都需要在数组中循环,并从该数组中收集所有
会话id
,然后相应地使用它们。如果您喜欢php,请给我一个例子