Insert multiple rows into table from a variable in PHP for Mysql & Oracle tables <p>I am fetching data from some tables &amp; storing it in a variable like below-:</p> <pre><code>$result = mysql_query("SELECT * FROM sample where column=mysql_insert_id()"); while($row=mysql_fetch_array($result)) { $str = "'". $row["name"] . "',". "'" . $row[quantity] . "'," . "'" . $row["id"]; } </code></pre> <p>So in my variable <code>$str</code>, suppose I have following values-:</p> <pre><code> shirt,10,1,pant,50,2....i.e. it will store values in a comma separated format. </code></pre> <p>Now I want to insert these values in another table say test-:</p> <pre><code>$qry = "INSERT INTO test(name,quantity,id)values(".$str."); </code></pre> <p>Now I want to store values in test table in two rows like-:</p> <pre><code>shirt 10 1 pant 50 2 </code></pre> <p>So how to do the same for Mysql &amp; Oracle tables?</p> <p>Plz help</p> <p>See my below query-:</p> <pre><code> $query2 = "SELECT sfoi.name, sfoi.sku, sfoi.qty_ordered, sfoi.price, sfoi.row_total, sfo.base_subtotal, sfo.base_shipping_amount, sfo.base_grand_total, (select mso.order_primary from mysql_sales_order mso where mso.increment_id =sfo.increment_id) FROM sales_flat_order sfo JOIN sales_flat_order_item sfoi ON sfoi.order_id = sfo.entity_id WHERE sfo.increment_id = ". $order_id ; $result_query2 = mysql_query($query2); </code></pre> <p>So for one order id i.e. for one order may contain more than 1 products i.e. many name,sku,quantity ordered etc. So at the time of mysql_fetch_array(), I want all product data in a single variable...my code for fetching is like this-: </p> <pre><code>while($row = mysql_fetch_array($result_query2)) { $string = "'". $row["name"] . "',". "'" . $row["sku"] . "'," . "'" . $row["qty_ordered"] . "',". "'" . $row["price"] . "'," . "'" . $row["row_total"] . "'," . "'" . $row["base_subtotal"]. "'," . "'" . $row["base_shipping_amount"] . "'," . "'" . $row["base_grand_total"] ."'," . $row["prod_foreign"]; $query3 = "INSERT into mysql_sales_product(name, sku, qty_ordered, price, row_total, base_subtotal,base_shipping_amount,base_grand_total,prod_foreign) VALUES(".$string.")"; } $result_query_product_outbound = mysql_query($query3); </code></pre> <p>Here I want to store result of mysql_ fetch_array in variable in such a way that if there are multiple rows I can still able to pass those rows using variable$string. e.g-: </p> <pre><code>name sku qty_ordered price row_total subtotal shipping_amnt grand_total prod_foreign nokia nk 2 500 1000 1000 300 1300 11 sansung sam 3 400 1200 1200 500 1700 30 sony sny 4 200 800 800 200 1000 45 </code></pre>