Find specific value in comma list in database

谁说胖子不能爱 提交于 2019-12-02 10:07:32

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

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

Get the comma separated list, then try the php function explode() to get an array that you can loop over.

http://php.net/manual/en/function.explode.php

$target = "MTNOfficial";
$query = "select usersBought from table_name";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
    $users = explode("," $row['usersBought']);
    // may want to trim() here
    for ($i = 0; $i < count($users); i++) {
        if ($users[i] == $target) {
            //we found him!
        }
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!