简体   繁体   English

如何从PHP / MYSQL中的单个表中使用特定值获取包含多个值的多个列

[英]how to fetch multiple columns containing multiple values using a specific value from single table in PHP/MYSQL

I want to fetch multiple columns containing multiple values using a specific value from single table in PHP/MYSQL. 我想使用PHP / MYSQL中的单个表中的特定值来获取包含多个值的多个列。

My table structure is like, 我的表结构是这样的,

  id  | Name |  s_id   |
-----------------------------
  1   | aaa  | 3 10 13 | 
  2   | bbb  | 1 2 5 8 16 23 | 
  3   | ccc  | 1 3 11 19 25 | 
  4   | ddd  | 7 15 19 25 | 
  5   | eee  | 5 13 16 21 |

My query is, 我的查询是

"SELECT Name FROM table where s_id like '%1%'"

I should get the output as, 我应该得到输出,

bbb
ccc

but i'm getting all the names whose 'id' has '1' in its value, ie 1, 11, 19, 16, etc. What should i change in my code and table structure? 但是我得到的所有'id'值都为'1'的名称, ie 1, 11, 19, 16, etc.我应该在代码和表结构中更改什么? do i need to use any delimiter? 我需要使用任何定界符吗? am coding it in php. 我用php编码。 pls help me out. 请帮帮我。 Thanks in advance. 提前致谢。

如果您以相同的方式存储数据,则只需在要过滤的值之后留一个空格即可,就像这样“ SELECT SELECT FROM FROM table where s_id like'%1%'”

试试这个REGEXP '[[:<:]]1[[:>:]]'

"SELECT Name FROM table where s_id REGEXP '[[:<:]]1[[:>:]]'"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM