Mysql查询 - 如何使用包含?

In my table a column called group_members_id contains userid of 10 users. I've been trying to figure out how I can make a query with MySQL that fetch the details of that row if given userid matches any of those 10 userid.

"SELECT * FROM `table` WHERE `group_members_id`.contains('{$userid}')".

This code is not working. can anyone help me?

You can get use like this

"SELECT *
FROM `table`
WHERE `group_members_id` LIKE '%{$userid}%'"

Use like clause

"SELECT * FROM table WHERE group_members_id LIKE '%$userid%'";

First, always use group_member_id as foregin id and make that as int.

Second, never use integer value as string. it will help in other functions like sort etc.

Third, If you have stored integer value as string in the table then you can use as follows:

1.) Use the LIKE Clause keyword, along with percent signs in the string

"SELECT * FROM table WHERE group_members_id LIKE '%$userid%'";

2.) If you're looking for more a complex combination of strings than you've specified in your example, you could regular expressions (regex): See the MySQL manual for more on how to use them: http://dev.mysql.com/doc/refman/5.1/en/regexp.html

Considering all the user IDs are of INT type:

<?php
//$aUserIds is an array of  your User Ids.
$userIds = implode(",", $aUserIds);
$sQuery  = "SELECT * FROM table WHERE group_members_id IN (" +  $uSerIds + ")";

Alternatively, if they are of string types, use:

$userIds = implode(",", $aUserIds);
$sUserIds = "";
foreach($userId as $userIds)
{
   $sUserIds += "'" + userId + "'";
}
$sQuery  = "SELECT * FROM table WHERE group_members_id IN (" +  $sUserIds + ")";