-2

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

0

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

4 Comments

+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
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.
Do you know how to make loop for specifying values as for($i=0; $i=<10 $i++){ code for inserting values}
@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.
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);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.