Inserting multiple rows into MySql with one INSERT statement using PHP implode function
<p>I'm trying to insert multiple rows into MySql with only one <code>INSERT INTO</code> statement using the <code>implode</code> function. It was found from <a href="http://stackoverflow.com/questions/779986/insert-multiple-rows-via-a-php-array-into-mysql">here</a>.</p>

<p>My sample code goes below.</p>

<pre><code>$sql[]=array();
$len=count($colour_id);
for($i=0;$i&lt;$len;$i++)
{
     $sql[]='('.$colour_id[$i].', '.$_POST['prod_id'].')';
}

$l=count($sql);
foreach($sql as $temp)
{
     echo $temp;
}

echo 'insert into product_colour (colour_id, prod_id)values '.implode(',', $sql);
</code></pre>

<hr>

<p>The above code simply initializes the <code>$sql</code> array and the <code>foreach</code> loop iterates over the array and displays the content of the array as follows.</p>

<pre><code>Array(1, 1)(2, 1)(3, 1)
</code></pre>

<p>but while echoing the last statement (insert statement), it shows the following error.</p>

<pre><code>Notice: Array to string conversion in C:\wamp\www\wagafashion\ProductColour.php on line 70
insert into product_colour (colour_id, prod_id)values Array,(1, 1),(2, 1),(3, 1) 
</code></pre>

<p>(line no 70 means the last line in the above code snippet).
What changes should be made so that I can insert the values stored in the array into MySql database?</p>
