1
   -----ID 
         1
         5
         1,6
         3
         4
         1,36
         1

我有这些'1,6,36'号码要搜索。

它应该找到包含 1 OR 6 OR 36 的任何行(例如上表中总共 4 行)

我试过了

FIND_IN_SET(ID, '1,6,36')

ID IN (1,6,36)

他们都没有工作。

知道如何实现这一目标吗?

4

2 回答 2

1
FIND_IN_SET(1, ID) OR
FIND_IN_SET(6, ID) OR
FIND_IN_SET(36, ID)
于 2013-10-05T03:52:37.487 回答
0

You have to do a sql query called IN, and you should do it as follows:

$id_array = array(1, 6, 36)
$sql = "SELECT * FROM table WHERE id IN ($id_array)";
$search = mysqli_query($sql_connection, $sql);

Then to display, you have to do a PHP loop like follows:

while($ids = mysqli_fetch_array($search)) {
    echo '<h3>'.$ids['field_from_db'].'</h3><br />';
}
于 2013-10-05T03:47:42.380 回答