Home  >  Article  >  Backend Development  >  请问怎么通过$a将张三和李四的id同时写入到表B的a_id

请问怎么通过$a将张三和李四的id同时写入到表B的a_id

WBOY
WBOYOriginal
2016-06-23 13:44:17970browse

表A
id       name
1        张三
2        李四

$a=‘张三,李四’
请问怎么通过$a将张三和李四的id同时写入到表B的a_id
即:
表B
id       a_id
1        1,2


回复讨论(解决方案)

假定 表B 的 id 为自增字段

insert into 表B (a_id) select group_concat(id) from A表

不是这样,我是说要通过变量$a

如果$a='张三';
那么a_id的值就写入1

insert into 表B (a_id) select group_concat(id) from A表 where find_in_set(name, '$a')


那如果是修改update怎么写??

update 表B set a_id=(select group_concat(id) from 表a where find_in_set(name, '$a'))
 

Statement:
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