Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 匹配列值,它是逗号分隔的列值_Php_Mysql - Fatal编程技术网

Php 匹配列值,它是逗号分隔的列值

Php 匹配列值,它是逗号分隔的列值,php,mysql,Php,Mysql,我在一个表中有3列,名称为users。在邮政编码中,有多个邮政编码以逗号分隔 id ZIP_codes user_email 1 123,785,333 a@gmail.com 2 785,241,123 v@gmail.com 现在我还有一个表名是student id ZIP_code std_email 1 123

我在一个表中有3列,名称为users。在邮政编码中,有多个邮政编码以逗号分隔

 id        ZIP_codes            user_email  

 1          123,785,333         a@gmail.com
 2          785,241,123          v@gmail.com
现在我还有一个表名是student

id        ZIP_code          std_email  

 1          123              std1@gmail.com
 2          241              std2@gmail.com
student.zip_代码来自first.phpsecond.php,它与用户匹配。zip_代码。现在,如果123与其他表匹配,则仅a@gmail.com及v@gmail.com应该在241前到达v@gmail.com应该来

我的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; 
}
            ?>

我通过在集合中查找()解决了我的查询


从用户中选择*以在集合中查找($zip1,邮政编码)

您运行的
SET@search
行毫无意义。您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册,以了解在第1行的“REGEXP CONCAT('(^ |,)('、REPLACE(@search'、'、'|')、'(,|$))”附近使用的正确语法,或使用任何其他方法来执行此操作:
“SET@search='$zip_code'”平均值?为什么不只寻找像CONCAT(“%”,@search,“%”)这样的