我的数据库中有这些表:
表A:
id | haystack
-------------
1 | 682,401
2 | 351
表 B:
id | needle
-------------
1 | 352
2 | 682
3 | 978
我要做的就是检查表 A 中的干草堆是否包含表 B 中的任何针头。我在 PHP 中执行了以下代码:
$res_A = mysql_query('SELECT * FROM table_A');
while($row_A = mysql_fetch_array($res_A)){
$res_B = mysql_query('SELECT * FROM table_B');
while($row_B = mysql_fetch_array($res_A)){
if(strlen(strstr($row_A['haystack'], $row_B['needle']) > 0)){
echo 'I found this needle: '.$row_B['needle'].' in this haystack: '.$row_A['haystack'].'<br />';
}
}
}
但是,它不起作用。我试图弄清楚一整天,但没有机会。我需要提到干草堆和针列是 Varchars。
你能帮我解决这种情况吗?提前致谢!