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