Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Location
    Oregon
    Posts
    243
    Thanks
    23
    Thanked 10 Times in 10 Posts

    Copy rows from one table to another

    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.


    PHP Code:
    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";

    Last edited by DataTalk; 05-21-2011 at 03:40 PM.

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    242
    Thanks
    1
    Thanked 57 Times in 56 Posts
    PHP Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •