Reputation: 10162
-----ID
1
5
1,6
3
4
1,36
1
I have these '1,6,36'
number to search.
It should find any row that contains 1 OR 6 OR 36 (e.g. total 4 rows in the above table)
I tried
FIND_IN_SET(ID, '1,6,36')
ID IN (1,6,36)
None of them worked.
Any idea how to achieve this ?
Upvotes: 1
Views: 92
Reputation: 7123
FIND_IN_SET(1, ID) OR
FIND_IN_SET(6, ID) OR
FIND_IN_SET(36, ID)
Upvotes: 1
Reputation: 842
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 />';
}
Upvotes: 0