需要通过PHP运行mysql SELECT,其中两个数组彼此相等。
$sql = "SELECT * FROM around WHERE 'array_intersect($ar1, $ar2)'";
$resultsd = $conn->query($sql);
foreach($resultsd as $rowd) {
$sword[] = $rowd['TIM'];
}
找到匹配后,需要从mysql中的那个特定行拉出来。这需要在PHP中。
阵列来自:
$ar1 = array();
$sql = "SELECT * FROM blc WHERE ffv='$safe_username'";
$results = $conn->query($sql);
foreach($results as $row) {
$ar1[] = $row['vvvs'];
}
答案 0 :(得分:3)
给定两个数组,并希望对这些数组的交集执行查询:
$array1 = array("a" => "green", "red", "blue");
$array2 = array("b" => "green", "yellow", "red");
$result = array_intersect($array1, $array2);
$sql = "SELECT * FROM `around` WHERE `foo` IN ('" . implode("','", $result) . "')";
这导致查询:
SELECT * FROM `around` WHERE `foo` IN ('green','red')
交叉发生在查询之外,因为在数据可用于查询之前,仍然存在与数据有关的事情。实际上我会更整洁,并且这样做:
$results = "'" . implode("','", $result) . "'";
$sql = "SELECT * FROM `around` WHERE `foo` IN ({$results})";