RE: db insert question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Thursday 21 July 2005 15:02, Jim Moseby typed:
> > As far as I know, there is no way to insert 20 unique rows 
> of data into a
> > MySQL table without executing 20 queries.  Maybe someone 
> else here does(?).
> > Perhaps drop a note over on the MySQL list, since this is 
> really more an
> > SQL question than PHP. Sorry I couldn't help.
> 
> Yes, MySQL supports an extended insert syntax of insert into 
> foo (...) values 
> (...), (...), (...).
> 

Interesting!  Consulting the manual, I see that you are correct.  So the OP
would do something like:

$sql="insert into foo values ";
foreach($formdata as $thisdata){
  $sql.="($thisdata,...,...,...),";
}
$result=mysql_query($sql);

(of course the above code is broken, because it would leave an extra comma
at the end, but this is the general idea, no?)

JM  <== learns something new from this list every day!

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux