user3818576 user3818576 - 2 years ago 75
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?

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download