jbrill Posted November 15, 2007 Share Posted November 15, 2007 hey guys, just wondering what the mysql statment woudl look like if i wanted to transfer info from one table to another and then remove the info form the origional table. basically, i have one table, "cartitems" it as productid, productnumber, qty, price. on checkout i would like to transfer this exact info to another called "orders" with the same fields. then remove the info from "cartitems" Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted November 15, 2007 Share Posted November 15, 2007 First, I would query the cartitems table base on the productid. $sql = "SELECT * FROM cartitems productid = 'the product id you want goes here'"; $results = mysql_query($sql) or die(mysql_error()); $data = mysql_fetch_array($results, MYSQL_ASSOC); Then you will have the values you need to insert into the orders table such as "INSERT INTO orders VALUES ('', $data["productnumber"], $data["qty"]... and so forth.) Finally, you will delete from the cartitems table base on the original productid. Hope this is what you were looking for. Quote Link to comment Share on other sites More sharing options...
s0c0 Posted November 15, 2007 Share Posted November 15, 2007 Yes your best bet is to script this, your script you will need to have two database connections using one for the select and the other for the insert. Your other option is to move the actual table file. This is only advisable (and really not advisable) if you don't mind losing whatever unique information is in the table your are overwriting. It will require a database restart. If I were you I would go with the script much as ainoy31 suggested. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.