-1
我在表名中有3列是用户。在zip_codes,有多个逗号分隔的邮政编码。匹配列值,即逗号分隔列值
id ZIP_codes user_email
1 123,785,333 [email protected]
2 785,241,123 [email protected]
现在我有其他的表名是学生。
id ZIP_code std_email
1 123 [email protected]
2 241 [email protected]
student.zip_code从first.php来源以及second.php,它与users.zip_codes匹配。现在,如果与其他表匹配,那么只有[email protected]和[email protected]应该来,并应由241 [email protected]来。
我的代码second.php是:
<?php
extract($_POST);
"SET @search = '$zip_code'";
$SQLSELECT = "SELECT * FROM users where REGEXP CONCAT('(^|,)(', REPLACE(@search, ',', '|'), ')(,|$)')";
$result_set = mysql_query($SQLSELECT) or die(mysql_error());
while($row = mysql_fetch_array($result_set))
{
extract($row);
echo $user_email;
}
?>
但它不能正常工作。
而且没有一点是你运行'SET @ search'行的。 – aynber
您的SQL语法有错误;检查对应于您的MariaDB服务器版本的手册,以找到在'REGEXP CONCAT('(^ |,)(',REPLACE(@search,',','|'),'),')(,| $ )')'在第1行 – user3526766
或任何其他方法来做到这一点? – user3526766