首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在php中使用array_intersect函数而不是MySQL交集?

如何在php中使用array_intersect函数而不是MySQL交集?
EN

Stack Overflow用户
提问于 2014-02-20 13:39:16
回答 1查看 186关注 0票数 0

我已经从php-MySQL中的几个sql短语中得到了结果。我的$sql1和结果查询短语如下所示。

代码语言:javascript
复制
$sql1= "SELECT code_co.code, code_co.disease_co, code_en.disease_en, ds.ds_url 
 FROM code_co
 LEFT JOIN code_en ON code_en.code = code_co.code
 LEFT JOIN note ON note.code = code_co.code
 ...
 where condition
$result1=  mysqli_query($con,$sql1);

但是我有9个sql查询短语,就像上面的代码一样。9 sql查询中的选定列相同。那是

代码语言:javascript
复制
$sql2= "SELECT code_co.code, code_co.disease_co, code_en.disease_en, ds.ds_url 
 FROM code_co
 LEFT JOIN code_en ON code_en.code = code_co.code
 LEFT JOIN note ON note.code = code_co.code
 ...
 where condition
$result2=  mysqli_query($con,$sql2);
...
$sql9= "SELECT code_co.code, code_co.disease_co, code_en.disease_en, ds.ds_url 
 FROM code_co
 LEFT JOIN code_en ON code_en.code = code_co.code
 LEFT JOIN note ON note.code = code_co.code
 ...
 where condition
$result9=  mysqli_query($con,$sql9);

最后,我想得到9个结果的交集,但不支持MySQL。所以我想通过php代码来解决这个问题。这就是array_intersect()函数。但我对如何使用它感到困惑。

代码语言:javascript
复制
 while($row1= mysqli_fetch_array($result1))

 while($row2= mysqli_fetch_array($result2))
     ....
 while($row9= mysqli_fetch_array($result9))

$intersect = array_intersect($row1, $row2, $row3, $row4, ...., $row9);
print_r($intersect);
mysqli_close($con);
?>

没有错误消息,但未显示任何内容。我首先在这段代码中使用了array_intersect函数。请给我一个建议。谢谢您的关心。

EN

回答 1

Stack Overflow用户

发布于 2014-02-20 16:54:44

用PHP做这件事将是致命的,并且是高度的资源消耗。如果您只是在要交集的键字段上使用as条件在所有大型查询之间进行内连接,那么您将直接获得您要查找的交集。

另一件事,可能什么都没有显示,因为你没有抛出任何错误到屏幕上,检查你的系统和应用程序中的PHP错误配置,以便在开发时启用它们。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21899119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档