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

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

WBOY
Release: 2016-06-23 13:44:17
Original
996 people have browsed it

表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表
Copy after login

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

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

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


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

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

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