Alex Chen Alex Chen - 10 months ago 37
MySQL Question

How to cast string to list in PHP or MySQL

I have a list of ids I want to fetch data from a Database.

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

Here is my query

$this->Execute("SELECT * FROM table WHERE id in (?)",array($ids));

This only gives my result where id=1. How do I fetch data where id is from 1 to 4?


Use FIND_IN_SET since $ids is a string

$this->Execute("SELECT * FROM table WHERE FIND_IN_SET(id, ?)", array($ids));