Forum Moderators: coopster
Can anyone help with the following issue I have.
Basically I have a shop basket which stores a new line per item detailing the customers id name and quantity.
When the customer checkouts out i want to transfer all lines in the basket which relates to the user and store these as new lines in the checkout table. the checkout table will then have a couple of additional information to be added.
So far I have no code as am not really sure where to start.
I do have
$userid = $_SESSION['user_id'];
$sql = "SELECT * FROM shop_basket WHERE cust_id = '$userid'";
$result = mysql_query($sql) or die("Error: " . mysql_error());
Can I then do the following?
while($basket = mysql_fetch_array($result)){
/* Then do the sql */
INSERT INTO ...
DELETE ...
}
THanks
insert into shop_checkout (col1, col2, ...) select col1, col2, ... from shop_basket WHERE cust_id = '$userid'
And as jatar_k mentioned, delete everything afterwards:
delete from shop_basket WHERE cust_id = '$userid'
This should be more efficient too since you don't need to fetch all the data back and forth.