您好我正在尝试将 2 个数组中的值与此查询进行比较,这是我知道的唯一方法:
$session = "1,2,3,"
$table_name = "table1";
$column_name = "data1"; // value for test is 1,4,5,
$sql = "";
$sql .= "SELECT * FROM $table_name WHERE ";
$franquia = array();
$franquia = explode(",", $session);
if (!empty($franquia)) {
$final_id = array();
foreach ($franquia as $val) {
if (trim($val) != '') {
$final_id[] = $val;
}
}
$count_data = count($final_id);
foreach ($final_id as $key => $id) {
if ($id > 0) {
$sql .= " $id IN ($column_name) ";
if ($key < $count_data - 1) {
$sql .= "OR ";
}
}
}
}
echo $sql;
我有1,2,3
on$session
和1,4,5
on的值,因此和$data1
之间的比较应该返回 true,因为它们的值都为 1,但我没有得到任何结果。$session
$data1
实际上它只有在两个数组相同的情况下才有效,比如$session = 1,2,3
和$data1 = 1,2,3
我究竟做错了什么?