在PHP for Mysql和Oracle表中的变量中将多行插入表中

I am fetching data from some tables & storing it in a variable like below-:

$result = mysql_query("SELECT * FROM sample where column=mysql_insert_id()");
while($row=mysql_fetch_array($result))
{
   $str = "'". $row["name"] . "',". "'" . $row[quantity] . "'," . "'" . $row["id"];
}

So in my variable $str, suppose I have following values-:

 shirt,10,1,pant,50,2....i.e. it will store values in a comma separated format.

Now I want to insert these values in another table say test-:

$qry = "INSERT INTO test(name,quantity,id)values(".$str.");

Now I want to store values in test table in two rows like-:

shirt    10   1
pant     50   2

So how to do the same for Mysql & Oracle tables?

Plz help

See my below query-:

    $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);

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-:

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);

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-:

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

For Oracle, like below :

INSERT ALL
   INTO your_table(column1,column2,column3) VALUES('values1.1', 'values1.2', 'values1.3')
   INTO your_table(column1,column2,column3) VALUES('values2.1', 'values2.2', 'values2.3')
SELECT * FROM dual;

Easier than doing a PHP loop, you can do this directly in MySQL. I'm not sure this is an option for you, since you didn't told us what the matter with Oracle...

Anyway, here is what I would do in your case:

INSERT INTO test(name,quantity,id)
SELECT name, quantity, id FROM sample where id=<your id here>

Or, if you have multiple ids,

INSERT INTO test(name,quantity,id)
SELECT name, quantity, id FROM sample where id in (<your ids here as comma separated list>)