Home >Backend Development >PHP Tutorial >How to use the mysql function to convert the string '1,2,3' into '1', '2', '3'?
The data retrieved from the database is a string like this:'1,2,3'
The sql I want to write now is like this: select * from a where id in('1','2',' 3');
How to realize that '1,2,3' becomes '1','2','3'?
Don’t use a foreach loop and query one record each time.
The data retrieved from the database is a string like this:'1,2,3'
The sql I want to write now is like this: select * from a where id in('1','2',' 3');
How to realize that '1,2,3' becomes '1','2','3'?
Don’t use a foreach loop and query one record each time.
This sql can be executed correctly: select * from a where id in (1,2,3);
So you can just splice the sql directly.
$str = '('.'1,2,3 '.')';
$sql = select * from a where id in $str;