我正在尝试从MYSQL中选择数据行,并将其作为数组行插入到具有一些附加数据的NEW DATABASE中。 请帮忙,这个脚本无效:
// there is some script and here goes fetching-inserting script:
<?php
include ('connection.php');
$query="SELECT * from savatcha where mem_id='$mem_id' ORDER BY nomination ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
$grand_total=0;
while ($i < $num)
{
$savatcha_id=mysql_result($result, $i, "savatcha_id");
$s_mem_id=mysql_result($result, $i, "s_mem_id");
$mem_id=mysql_result($result, $i, "mem_id");
$tovar_id=mysql_result($result, $i, "tovar_id");
$nomination=mysql_result($result, $i, "nomination");
$price=mysql_result($result,$i,"price");
$quantity=mysql_result($result,$i,"quantity");
$total_row=$price * $quantity;
$grand_total += $total_row;
?>
<?php
include ('order_connection.php');
mysql_query("INSERT INTO order_list(order_id, s_mem_id, mem_id, firm_name, grand_total, order_method, order_date)VALUES('$order_id', '$s_mem_id', '$mem_id', '$firm_name', '$grand_total', 'Bank hisob raqami orqali', '$date')");
mysql_close();
?>
<?php
++$i;
}
?>
答案 0 :(得分:0)
而不是从数据库中获取数据,将它们加载到php
数组并将其插回到另一个表中,您只需使用此mysql
查询。
INSERT INTO databasename2.tablename2(field1,field2,fieldn,fielda,fieldb) SELECT field1,field2,fieldn,valuea,valueb FROM databasename1.tablename1