【问题标题】:find and select from a coma separated values mysqli and an array从逗号分隔值mysql和数组中查找并选择
【发布时间】:2015-11-22 14:02:25
【问题描述】:

大家好,我正在做一个项目,只有当它包含数组的任何值时,我才需要选择字段

我的意思是

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

 $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);

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

【问题讨论】:

标签: php mysql arrays mysqli


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-02-14
    • 2021-12-10
    • 2020-12-16
    • 1970-01-01
    • 2012-04-11
    • 2021-01-19
    • 1970-01-01
    • 2016-04-02
    • 1970-01-01
    相关资源
    最近更新 更多