我正在使用codeigniter,并且是codeigniter的新手。我将物品添加到购物车表中。现在我想将购物车记录复制到我的tblShoppingCart
表中吗?
任何人都可以举例说明将购物车记录复制到另一张表吗?public
function purchase() {
$userid = $this -> session -> userdata('user_id');
foreach (serialize($this->cart->contents()) as $cart) {
$userid = $userid;
$item_id = $cart['id'];
$quantity = $cart['qty'];
$price = $cart['price'];
$total = $cart['subtotal'];
$this -> db -> insert('tblShoppingCart', array('tblLoginID' => $userid,'tblItemsID' => $item_id, 'Qty' => $quantity, 'price' => $price, 'total' => $total));
}
$this -> cart -> destroy();
return TRUE;
}
答案 0 :(得分:1)
您可以使用$this->cart->contents()
if ($cart = $this->cart->contents()){
foreach ($cart as $item){
$order_detail = array(
'product_id' => $item['id'],
'pro_quantity' => $item['qty'],
'pro_price' => $item['price']
);
$this->db->insert('table_Name', $order_detail);
} }