Lucas de Roo Lucas de Roo - 7 months ago 10
SQL Question

Get multiple records with one string

I have 4 rows in my database. They all got a different id starting at 1.

i have a string with multiple id's.

$str = "1,2,3,4";


How can i get all the records with id 1,2,3 and 4?

SELECT * FROM table_name WHERE id = $str


Thanks in advance.

Answer

try this:

SELECT * FROM table_name WHERE id IN ($str)