Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.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 获取“结果”(“select*from table”其中id在($array)中),但它假定$array为;数组";_Php_Mysql_Wordpress - Fatal编程技术网

Php 获取“结果”(“select*from table”其中id在($array)中),但它假定$array为;数组";

Php 获取“结果”(“select*from table”其中id在($array)中),但它假定$array为;数组";,php,mysql,wordpress,Php,Mysql,Wordpress,我需要将一个数组从get\u results()传递到另一个查询调用get\u results() 我的代码如下: $getids = get_results("Select ID from table_name"); $getData = get_results("Select name from table where ID In($getids)"); 但是当我运行此代码而不是$getids时,它将数组$getids放在一个数组中。您需要以逗号分隔的字符串形式传递所有ID,如下所示:

我需要将一个数组从
get\u results()
传递到另一个查询调用
get\u results()

我的代码如下:

$getids = get_results("Select ID from table_name");

$getData = get_results("Select name from table where ID In($getids)");

但是当我运行此代码而不是
$getids
时,它将
数组

$getids放在一个数组中。您需要以逗号分隔的字符串形式传递所有ID,如下所示:

$getids = get_results("Select ID from table_name");
$getids = implode( ',', $getids );
$getData = get_results("Select name from table where ID In($getids)");

由于
$getids
是一个数组,如果您尝试将其作为字符串回显,您将得到单词
array
。相反,您需要使用它来获得逗号分隔的值列表,即

$getData = get_results("Select name from table where ID In(" . implode(',', $getids) . ")");
但是,您可以通过在查询中使用
JOIN
直接获得所需的数据:

$getData = get_results("SELECT name 
                        FROM `table` t1
                        JOIN table_name t2 ON t2.ID = t1.ID");

$getids是一个php数组,要在字符串变量中使用,必须使用“内爆”函数:

//first check array is not empty
if(count($getids))
{
  //if your array is same as: $getids=array("ID"=>[1,2,3,4]) you must first convert it to flat array same as :$getids=[1,2,3,4] 
  // for example: $getids=$getids["ID"];
  $sql="Select name from table where ID In(".implode(",",$getids).")";
}

$getids
在数组中。您需要以逗号分隔的字符串形式传递所有ID。请在发布前检查您的代码。PHP中没有名为
impload