简体   繁体   中英

MySql explode/in_array functionalilty

In my table I have a field with data such as 1,61,34 , and I need to see if a variable is in that.

So far I have this

SELECT id, name FROM siv_forms WHERE LOCATE(TheVariable, siteIds) > 0

Which works, with the exception that if the siteIds were 2,61,53 , and TheVariable was 1 , it would return the row as there is a 1 in 61. Is there anyway around this using native MySql, or would I need to just loop the results in PHP and filter the siteIds that way?

I've looked through the list of string functions in MySql and can't see anything that would do what I'm after.

Try with find_in_set function.

SELECT id, name FROM siv_forms WHERE find_in_set(TheVariable, siteIds);

Check Manual for find_in_set function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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