dopcpc9207
2015-06-06 08:36
浏览 448
已采纳

laravel查询逗号分隔字符串的位置

Using Laravel to check if a value is in an array stored as comma delimited string, example string stored in mysql table 1,14,15,20,25

So I'm trying to add comma's at the start and end to search appropriately

$query = Profile::whereRaw("',' + cf_profile.sub_category_id + ',' LIKE '%,$sub_category->sub_category_id,%'");

Can anyone let me know where I'm going wrong here, as it's returning no results.

图片转代码服务由CSDN问答提供 功能建议

使用Laravel检查数值是否存储为以逗号分隔的字符串存储的数组,存储在mysql表1中的示例字符串 ,14,15,20,25

所以我试图在开始和结束时添加逗号以正确搜索

  $  query = Profile :: whereRaw(“','+ cf_profile.sub_category_id +','LIKE'%,$ sub_category-> sub_category_id,%'”); 
   
 
 <  p>任何人都可以让我知道我在哪里出错,因为它没有返回任何结果。 
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douse8732 2015-06-06 08:40
    已采纳

    You can use FIND_IN_SET():

    WHERE FIND_IN_SET($sub_category, sub_category_id) > 0
    
    点赞 打赏 评论

相关推荐 更多相似问题