Yes there is, it's kind of a hack...

If you insert using "values" you can only insert 1 row:

INSERT foo (col1, col2, col3)
  VALUES("Moe", "Larry", "Curley")

But if you use a select statement it will insert as many rows as the select
returns:

INSERT foo (col1, col2, col3)
  SELECT col1, col2, col3
   FROM bar
   WHERE ...

So the hack is to be able to insert static values (OK PHP Variables - but to
the query they look static) into a table as often as you like.  Create a new
table "Counter" with one integer field "count", we'll have the integers in
it 1, 2, 3, 4,  ... Up to the maximum you think  you'll want to insert.

Now you can combine the two methods to get what you were after:

INSERT foo (col1, col2, col3)
  SELECT "Moe", "Larry", "Curley"  /* substitute your PHP variables here */
   FROM Counter
   WHERE count <= $numOfRowsYouWanted

OK?  Now why are you doing this in the first place?  It violates one of the
rules of good DB design (having identical information in more than one
place).  I'll bet there's a better way to do what you're trying to do here.

Frank


On 5/31/02 12:13 PM, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:

> From: Leif K-Brooks <[EMAIL PROTECTED]>
> Date: Fri, 31 May 2002 15:12:21 -0400
> To: [EMAIL PROTECTED]
> Subject: Mutiple inserts with one query?
> 
> Is there a way to insert multiple identical rows in one mysql query?
> I'm using a looped query right now, which uses more server load than it
> should...  Thanks!
> 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to