Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
how could i reduce the following piece of code:

for ($num=0;$num<50;$num++) {
  mysql_query($db,"INSERT INTO whatever (stuff) VALUES (somevalue);";
  mysql_query($db,"INSERT INTO sometable VALUES

to something where only two sql queries are made (as opposed to 100?).
 ie. where the first line could be converted to something like this:

mysql_query($db,"INSERT INTO whatever (stuff) VALUES

where somearray contains every somevalue.

Re: mysql_insert_id

Carved in mystic runes upon the very living rock, the last words of
yawnmoth of comp.lang.php make plain:

Quoted text here. Click to load it

I don't know if you're aware of extended insert format:

  insert into Table (f1, f2) values (v1a, v2a), (v1b, v2b)....

However, mysql_insert_id() will only return the value for the first
record. What you could do, though, is this:

  $FirstID = mysql_insert_id();
  $Query = "select ID from Table where ID>=$FirstID limit 0, $NumRows";

Where $NumRows is the number of rows you inserted. Since all the rows
were inserted by one query, they will have consecutive IDs.

Alan Little
Phorm PHP Form Processor /

Site Timeline