gpt4 book ai didi

php - 从逗号分隔值 mysql 和数组中查找并选择

转载 作者:行者123 更新时间:2023-11-29 21:48:54 25 4
gpt4 key购买 nike

大家好,我正在开发一个项目,仅当该字段包含数组的任何值时,我才需要选择该字段

我的意思是

我有一个类似的字符串(逗号分隔)

 $string =1,2,3,4,5,7;

我有一个数据库,其中包含一个表的重量值,例如

 1,9 // this is one of the field which conatins the id of people who should be notified

现在我想选择包含字符串中任何值的所有字段,例如

如果字符串类似于

  $string =1,7;

 field contains 1,8
filed2 contains 9,88
field3 contains 2,5,6,7,8

然后仅选择 1 和 3 个字段

我已经尝试过了

      select aid,a.cid,tdid,fdid,mcat,sub,a.mess,attach,prio,sdate,edate,stime,etime,a.date,d.name,d.photo,c.curl,c.cname 
from activity a,dept d,enter c where
((CONCAT(",", tdid, ",") REGEXP ",('.implode("|",$arr).'),") and tdid=d.did and d.acid=c.cid)
$mydeptslist=1,8
$arr=array($mydeptslist);

即使值匹配,此代码也不会选择任何内容..请建议我其他内容....我有一个动态字符串..

最佳答案

MySQL函数find_in_set()只能搜索一组字符串中的一个字符串。您可以尝试这样的操作

find_in_set('1',comma_sep_field_name) OR find_in_set('7', comma_sep_field_name) 

关于php - 从逗号分隔值 mysql 和数组中查找并选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33855619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com