Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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中将资源传递到查询的参数中吗?_Php_Mysql_Database - Fatal编程技术网

您可以在PHP中将资源传递到查询的参数中吗?

您可以在PHP中将资源传递到查询的参数中吗?,php,mysql,database,Php,Mysql,Database,所以我有一个声明: $r = mysql_query("Select type from boats where type like '%speed%'"); 然后我可以将构造的资源应用于另一个查询吗 $r2 = mysql_query("select * from assets where type in ".$r); 我正在尝试做类似的事情 select * from assets where type in (select type from boats where type l

所以我有一个声明:

 $r = mysql_query("Select type from boats where type like '%speed%'");
然后我可以将构造的资源应用于另一个查询吗

 $r2 = mysql_query("select * from assets where type in ".$r);
我正在尝试做类似的事情

 select * from assets where type in (select type from boats where type like '%speed%')
不,你不能这样做

但是您可以组合sql

$sql = "Select type from boats where type like '%speed%'";
$r = mysql_query($sql);
$r2 = mysql_query("select * from assets where type in ($sql)");
或者可以使用联接代替子查询

$r2 = mysql_query("select a.* from assets a 
                   join boats b on a.type = b.type and b.type like '%speed%'");

我甚至不知道为什么这被否决了(谢谢@xdazz,我想这是一个很好的答案。我一直在想这个问题。我只是不喜欢第二次查询它的想法,而且,它是多余的。这将不得不这样做。