请看看: (oid,iid,名字,类型)VALUES(5,X3,john,拳击手) 我想插入oid。它来自另一个表$ oid = mysql_fetch_array ['oid'];其中iid名称和类型相同。我可以只在一个声明中插入这些
答案 0 :(得分:6)
INSERT查询可能有许多值集:
INSERT INTO table (oid, iid, name, type) VALUES (5, 'X3', 'john', 'boxer'), (8, 'X3', 'john', 'boxer'), (10, 'X3', 'john', 'boxer')...
http://dev.mysql.com/doc/refman/5.5/en/insert.html
您需要为要插入的所有列指定所有值,即使它们在多行中相同也是如此。
答案 1 :(得分:3)
$query = "INSERT INTO your_table
(oid, iid, name, type)
VALUES
(5, 'X3', 'john', 'boxer'),
(8, 'X3', 'john', 'boxer'),
(10, 'X3', 'john', 'boxer'),
(11, 'X3', 'john', 'boxer'),
(60, 'X3', 'john', 'boxer'),
(220, 'X3', 'john', 'boxer'),
(311, 'X3', 'john', 'boxer'),
(336, 'X3', 'john', 'boxer'),
(339, 'X3', 'john', 'boxer'),
(800, 'X3', 'john', 'boxer');";
$result = mysql_query($query);