我從一些表&獲取數據的變量存儲它像如下─在PHP中一個變量:插入多行到表從爲MySQL和Oracle表
$result = mysql_query("SELECT * FROM sample where column=mysql_insert_id()");
while($row=mysql_fetch_array($result))
{
$str = "'". $row["name"] . "',". "'" . $row[quantity] . "'," . "'" . $row["id"];
}
所以在我的變量$str
,假設我有下列值 - :
shirt,10,1,pant,50,2....i.e. it will store values in a comma separated format.
現在我要插入另一個表中這些值測試 - 說:
$qry = "INSERT INTO test(name,quantity,id)values(".$str.");
現在我要存儲在兩行的測試表中的值喜歡 - :
shirt 10 1
pant 50 2
因此,如何爲MySQL & Oracle表一樣嗎?
plz幫助
見我下面的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);
所以對於一個訂單編號,即對於一個訂單可能包含超過1種產品,即許多名稱,SKU,訂購數量等,所以在mysql_fetch_array()的,我想在一個單變量的所有產品數據的時間......我爲取碼就像是這個 - :
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);
在這裏,我想存儲mysql_ fetch_array的結果變數的一種方式,如果有多行,我仍然可以使用變量$字符串傳遞這些行。例如:
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
在1 st插入,你有一個bug:你應該生成一個像「('shirt',10,1),('part',50,2)」 – haltabush 2012-03-23 07:11:29