dronthpi05943 2014-02-20 05:39
浏览 66

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

I have got the results from the several sql phrase in php-MySQL. My $sql1 and the result query phrases is as like below.

$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);

But I have the 9 sql query phrases as like above code. selected columns are same in the 9 sql query. That is

$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);

Finally I want to get the intersection of the 9 results, but MySQL is not supported. So I want to solve that by php code. That is array_intersect() function. But I am at a loss how I use that.

 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);
?>

There is no error message but, nothing is displayed. I first use array_intersect function in this code. please, Give me a piece of advice. Thank you for your concern.

  • 写回答

1条回答 默认 最新

  • dopzc64662 2014-02-20 08:54
    关注

    Doing it with PHP is going to be DEATHLY, and highly resource consumer. If you just made an INNER JOIN between all big queries using as condition in the ON the key field you want to intersect, you'd directly have the intersection you look for.

    Other thing, maybe nothing is displayed because you're not throwing any error to the screen, check your PHP error configuration in your system and application to enable them where developing.

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行