user3818576 user3818576 - 4 months ago 8x
PHP Question

show the list of selected id in mysql php

I have a list of id in my array.
These are the id of my rows that I want to display only in mysql

$id = array(12,13,14,15,16);

I want to query only the value in my array to mysql.
I try WHERE IN in mysql but it shows all rows.

How can I display the row of mysql that have the same id in my array?


Before all you need to convert your array to string by

$ids = implode(',', $id);

Hi can you please try FIND_IN_SET Like example

SELECT * FROM users WHERE FIND_IN_SET(id,'$ids')

And if you want to use IN then

SELECT * FROM users WHERE id IN ($ids)