Home > Backend Development > PHP Tutorial > How to use the mysql function to convert the string '1,2,3' into '1', '2', '3'?

How to use the mysql function to convert the string '1,2,3' into '1', '2', '3'?

WBOY
Release: 2016-09-14 09:41:21
Original
1941 people have browsed it

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.

Reply content:

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;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template