在数据库的逗号列表中查找特定值 [英] Find specific value in comma list in database

查看:58
本文介绍了在数据库的逗号列表中查找特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一张表中,我有一列,其中有一个用逗号分隔的已购买该商品的用户列表. 图像

In one of my tables, i have a column where it has a comma seperated list of users that have bought that item. IMAGE

我如何阅读列表并运行php脚本以查找已登录(存储在会话中)的用户是否在该列表中.例如,如何查看登录用户(MTNOfficial)是否在列表中.我认为它是使用MySQL CONCAT或FIELD_IN_SET之类的php if语句.

How can i read the list and run a php script to find if the user that is logged in (that is stored in the Session) is in that list. For example, how could i see if the logged on user (MTNOfficial) is in the list. I think its a php if statement with a mysql CONCAT or FIELD_IN_SET or something.

谢谢

推荐答案

使用

Use FIND_IN_SET() to find the records that contain your user

select *
from your_table
where find_in_set('MTNOfficial', usersBought) > 0

这篇关于在数据库的逗号列表中查找特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆