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 如何从一组选项中返回多个结果?_Php_Mysql - Fatal编程技术网

Php 如何从一组选项中返回多个结果?

Php 如何从一组选项中返回多个结果?,php,mysql,Php,Mysql,我有一组数据: $ary = new array( array("domain"=>"domain1", "username"=>"username1"), array("domain"=>"domain1", "username"=>"username2"), array("domain"=>"domain2", "username"=>"username3"), ); 我需要使用这些数据从MySql数据库中检索数据,下面的表结构为

我有一组数据:

$ary = new array(
    array("domain"=>"domain1", "username"=>"username1"),
    array("domain"=>"domain1", "username"=>"username2"),
    array("domain"=>"domain2", "username"=>"username3"),
);
我需要使用这些数据从MySql数据库中检索数据,下面的表结构为说明而简化

domain_table
    domain_id
    domain

user_table
    user_id
    user

stuff_table
    stuff_id
    ... details

link_table
    link_id
    user_id   -- The user we are searching for connections on
    connected_user_id   -- from the array above
    stuff_id
我需要获取stuff表中每一行的单个用户id,该用户id也具有来自数组的已连接用户id

我在用PDO

在$ary中可能有成百上千个条目

我可以通过在数组中循环并添加连接负载来生成一个非常大的查询。 我可以对$ary中的每一行执行单个查询。 我可以用$ary创建一个临时表并使用联接。 还有别的吗

实现这一目标的最佳方式是什么?最快的处理器时间,而不是太神秘

由于速度较慢,因此对每一排床身通道执行一次查询 许多人比一个人好。 如果可能-查看并使用它。
如果您的整个数据集很大,并且无法放入内存,那么连接不应该是您的选择

进行顺序选择。从链接表中选择行,在PHP中从结果中收集用户id。然后使用where user\u id从user\u表中选择行。在PHP中处理结果分组

即使是大表,按键选择也会很快。有2-5个选择而不是1个选择不是问题


当您的数据库适合RAM时,连接将很快。然后问题就出现了。

RE:joins。即使所有联接都在主键上,这是真的吗?