Re: Multiple insertion querry

From: Nikolai Chuvakhin (nc_at_iname.com)
Date: 11/19/03


Date: 19 Nov 2003 14:30:44 -0800

Eric Kincl <Eric@Kincl.net_NO_SPAM_> wrote
   in message news:<3fbbcc1f@news.gvsu.edu>...
>
> I have an array of data in PHP. I would like to insert each
> member of the array into it's own row in SQL. The array is
> of variable length, so it would have to be dynamic code.
> How would I go about this?

By compiling one hell of a long query and executing it at once.
This is much faster than any solution with multiple INSERTs.

$array = array ('Many', 'many', 'many', 'members');
$query = "INSERT INTO yourtable (yourcolumn) VALUES (('" .
         implode ("'), ('", $array) .
         "'))";
$result = mysql_query ($query);

If I put in the right punctuation, the variable $query must
contain:

INSERT INTO yourtable (yourcolumn)
  VALUES (('Many'), ('many'), ('many'), ('members'))

Cheers,
NC



Relevant Pages

  • Re: field names in column
    ... I'm making a database of Dutch wind mills. ... query usually gives just a few rows, ... What you need to do is read the data into an array so you have it all ...
    (alt.php)
  • Re: field names in column
    ... I'm making a database of Dutch wind mills. ... query usually gives just a few rows, ... What you need to do is read the data into an array so you have it all there, then output it from the array in the order you want, i.e. ...
    (alt.php)
  • Re: Mix/Max/Avg Help based on dynamic ranges
    ... Did you enter Biff's formula as an array? ... The query I gave you is dependent on your breaking out the ranges as Biff ... Where Nums are the values to avg based on the head count range. ... deemed optimal for building device profiles based on locn size and device ...
    (microsoft.public.excel.worksheet.functions)
  • RE: [PHP] Looking for help with forms/variables and an array!
    ... [PHP] Looking for help with forms/variables and an array! ... Basically all I am trying to accomplish is 2 separate SQL query filter ...
    (php.general)
  • Re: Imitating Mail Merge on server
    ... given moment we know which data (in this case, customers) is being worked ... and concantenate each query together. ... loop the array, plug in the current recordset value. ... We have close to fifty tokens that we use in the application correspondence, ...
    (microsoft.public.inetserver.asp.general)