while 循环中的数组匹配

问题描述 投票:0回答:1

我正在为我的项目开发一个搜索工具,

我想要的输出是从不同的表中获取共同的值。例如)SKR0BP100

如何得到这个值?

当我在 for 循环中运行程序并从 while 循环中获取值时,现在如何使用 array_intersect() 函数?因为对于数组相交函数,至少需要 2 个数组,但我一次只能得到一个数组,因为它在 for 循环上运行。所以我该怎么做 ??请帮助我!

$结果 = array_intersect($arr1, $arr2);

但是我一次只有一个 $array (即 $sid[$i] ,因为它在 for 循环中运行。

我的节目

for($i=0;$i<$cc;$i++)
{

$m1="select * from $u$sc where $b[$i]='$a[$i]' ";
$m2=mysql_query($m1);

echo"$m1<br><br>";

while($we=mysql_fetch_array($m2))
{
$sid[$i]=$we['SI'];

echo"$sid[$i]<br><br>";
}
    }

所需输出 = SKR0BP100

//如何获得这个?

当前输出

select * from Studentsc where Zone='East' 

SKR0BP100
SKR0BP12


select * from Studentsc where Area='Rural' 

SKR0BP129
SKR0BP13
SKR0BP100


select * from Studentsc where Class='12' 

SKR0BP100
SKR0BP101
php for-loop while-loop
1个回答
0
投票

因此,如果您想创建查询,请尝试这个

$where = array();
for($i=0;$i<$cc;$i++)
{
    $where[] = $b[$i]."='".$a[$i]."'";
}

$m1="select * from $u$sc where ".implode(" and ",$where); //If you are sure that atleast one value vomes
© www.soinside.com 2019 - 2024. All rights reserved.