Pleas see it: (oid, iid, name, type) VALUES (5, X3, john, boxer) I want to insert oid. It is from a different table $oid=mysql_fetch_array['oid']; where iid name and type is same. Can i insert thes at only one statement
2 Answers
An INSERT query may have many sets of values:
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
You will need to specify all values for all columns you wish to insert even if they are the same in multiple rows.
4 Comments
asprin
+1. I don't mind seeing this answer. I learnt a new thing today because of it. @mmmshuddup You're right on your grounds, but as you see there are advantages too
Yes Barry
Yeah. I was going to answer this question but then I said "no, it really is totally an exact duplicate of another question." ha oh well.
Fujael
Do you know how to make loop for specifying values as for($i=0; $i=<10 $i++){ code for inserting values}
Dan Grossman
@Fujael If you do not know how to write loops and create strings, you need to buy a book. That is too basic to ask for help with.
$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);