View Full Version : Copy rows from one table to another

05-21-2011, 03:14 PM
Is there a better way to do this?

Copy all orders from orders_temp_table WHERE OrderNo = $orderno , to the orders production table

The goal here is to copy the orders serverside without posting.

require_once("connection.php") ;

$q = mysql_real_escape_string($_GET["OrderNo"]);
$sql = ("SELECT * FROM `orders_temp_table` WHERE `OrderNo` = '{$q}'")
or die ("No Data Found");
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)) {

// now lets copy the order from the temp_table to the production_table
mysql_query("INSERT INTO `orders` (pid, Item, Price) VALUES ('$row[id]','$row[Item]','$row[Price]')")
or die ("No Data Found");
echo "Your order was a success";

05-21-2011, 04:42 PM
mysql_query("INSERT INTO `orders` SELECT * FROM `orders_temp_table` WHERE `OrderNo` = '$q'");
You must delete these records from orders_temp_table table after this query.